From patchwork Thu Jul 27 07:36:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuyi Zhou X-Patchwork-Id: 12681 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp963274vqo; Thu, 27 Jul 2023 02:12:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlHm3RrAaTAQwH8LbGoRXho+esx3gX6roCMgrkXvTM7elhXRL8dzUkD/sKJZrLzGA5Hxg21o X-Received: by 2002:a17:907:a0c6:b0:994:5340:22f4 with SMTP id hw6-20020a170907a0c600b00994534022f4mr1199175ejc.6.1690449174093; Thu, 27 Jul 2023 02:12:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690449174; cv=none; d=google.com; s=arc-20160816; b=lerAcbN6n7Novy59CVstZ1KPVDtD80GxxW0lencgH7aeTnYRy0D3IbrQCCS/5N2/hm vzBvo1y2R08Gn6k5MGTAHM9ngj5OctV/K+5q1cxyINBECloZpAxS1M3iQs6YNTo6KcW4 iEe7hWjjXk004+QfX8wwG48sKq7kbfJ5JgK0+Q0TvOA4YOw19D63yq3baj+nMe3n/5VD YmvJccjp1vtuKy/m1gXWkzRhhz/NLWVg7ASnRMamnIonOVVwATOwC+sSj5nvcou7LSi8 ybuvU5kcky64hevzmzfo4GDIH6WW+oXEYdCTyAMC08cP4/SD/R1az9KyKPtUktGFDpwv EItw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=QdW9TKjaVoY8TAoiZ9/Vr1Qx2UudtUG/Q1a9kCBPzGw=; fh=hkVHq7oq/x6T47Z/W+8iW7aAYD01qDHXzBTbsOMDe4M=; b=ij+vZ8nd1FbMab4u7D0DvsqIk4O65c4ioFQaD4Ud4IPBLhrXJs9PPM9mIm6WHSZcpv dZjW0u24YzbIcRWFEQEF2h/CB7gClq5hRrfZX2W/9rSjQ7mxdqCdva3s6XkN+UKBR6Ju g8lmQqMWnXTYvr3za5kFsh+foAMLNOjvkcmzov8jbs3OHrgtyjCFV6T3gGLhefCilLrS nCJMFI1fM2Uzw9ByQdryBqLB2l1xyZQVgPVjojG2Ni8HpMvHL+Q/oK1Ldv7xzn9CjuEh j0zl9Hngu4+zyGxzPeRmI5deLkyejzWbNkkr5JSFp9Sed/nvN7haqDyP4jycnJldGeUd NlMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=WJUfha13; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v19-20020a17090606d300b00992f2becb47si789858ejb.7.2023.07.27.02.12.31; Thu, 27 Jul 2023 02:12:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=WJUfha13; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233495AbjG0Hoy (ORCPT + 99 others); Thu, 27 Jul 2023 03:44:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233679AbjG0Hna (ORCPT ); Thu, 27 Jul 2023 03:43:30 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F44683EC for ; Thu, 27 Jul 2023 00:37:04 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-686ba29ccb1so383530b3a.1 for ; Thu, 27 Jul 2023 00:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690443423; x=1691048223; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=QdW9TKjaVoY8TAoiZ9/Vr1Qx2UudtUG/Q1a9kCBPzGw=; b=WJUfha13VzDGQgQyWyKoLGRPd9B2AkAKQKlD7TIy163bJUtKECJHVmywN3s0unJxcA AFA1yR4NNxwgvdmCB9kcHHQPMLl9LlV8pAcIGWlF0HUvZLVIlQEbvML2tpREm3u8AD4k ZViVO1tm0udVd0TVKE7yJTePILn0TB+bdWzMf3niDZWAHwzWJFTwp+C84Q2j6ViYWC5t 4N5Am2+2fKfp6XRRZQnrrgjY5wF7mYeeJH4JoDqHPFPB6qrHo39bwgcnuGX6byF15qjx ceejVzI8aCT+WIluxObIBO5wrLPWkAdawMcVjKG/3zRwdXvZXxv1sPDUtb817SM3m6vs XPfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690443423; x=1691048223; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QdW9TKjaVoY8TAoiZ9/Vr1Qx2UudtUG/Q1a9kCBPzGw=; b=a/fSoOccBDeP72ZQCBBari5VgNjsc6JgCgKeWxkG4BpHzs1jsAs1rcDjjoib6ZcfMm Dxjt/jg6s+q69DMDB18ratBDNqToPwdncZyrlwUya+Y61j+LYzGjWttst2UvEMJspE/X 9BDGEkPqieqEbETQIGf0vpqfq2Ui6LoCAO10yNzkiLDyak77TCLB9Yba4I6y2u6FJvcY ODPk0IRi1j+SauDft1MMmtyzP3SboloRHKI2RNq1QJAmvD/9IPUBaO4hMczy5dM0xAeM DvN/gpzhiwm5VIpvsY0Fy53998qspnJ+r9FV04JtS2KpuIyLaprp4ogEHh1ZBJpOnwDi 6C0g== X-Gm-Message-State: ABy/qLaeoX8o0lWK/gKzQxbHGuuung9AKjmA3gal1CiAp2i98zHSFmGH uUpxxc4iOLCqI5YjRJ9Vy6gwEw== X-Received: by 2002:a05:6a20:3c8f:b0:123:152d:d46b with SMTP id b15-20020a056a203c8f00b00123152dd46bmr2384597pzj.26.1690443423642; Thu, 27 Jul 2023 00:37:03 -0700 (PDT) Received: from n37-019-243.byted.org ([180.184.51.134]) by smtp.gmail.com with ESMTPSA id s196-20020a6377cd000000b005638a70110bsm733919pgc.65.2023.07.27.00.37.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 00:37:03 -0700 (PDT) From: Chuyi Zhou To: hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, wuyun.abel@bytedance.com, robin.lu@bytedance.com, Chuyi Zhou Subject: [RFC PATCH 0/5] mm: Select victim memcg using BPF_OOM_POLICY Date: Thu, 27 Jul 2023 15:36:27 +0800 Message-Id: <20230727073632.44983-1-zhouchuyi@bytedance.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772564259239758541 X-GMAIL-MSGID: 1772564433177582863 This patchset tries to add a new bpf prog type and use it to select a victim memcg when global OOM is invoked. The mainly motivation is the need to customizable OOM victim selection functionality so that we can protect more important app from OOM killer. Chuyi Zhou (5): bpf: Introduce BPF_PROG_TYPE_OOM_POLICY mm: Select victim memcg using bpf prog libbpf, bpftool: Support BPF_PROG_TYPE_OOM_POLICY bpf: Add a new bpf helper to get cgroup ino bpf: Sample BPF program to set oom policy include/linux/bpf_oom.h | 22 ++++ include/linux/bpf_types.h | 2 + include/linux/memcontrol.h | 6 ++ include/uapi/linux/bpf.h | 21 ++++ kernel/bpf/core.c | 1 + kernel/bpf/helpers.c | 17 +++ kernel/bpf/syscall.c | 10 ++ mm/memcontrol.c | 50 +++++++++ mm/oom_kill.c | 185 +++++++++++++++++++++++++++++++++ samples/bpf/Makefile | 3 + samples/bpf/oom_kern.c | 42 ++++++++ samples/bpf/oom_user.c | 128 +++++++++++++++++++++++ tools/bpf/bpftool/common.c | 1 + tools/include/uapi/linux/bpf.h | 21 ++++ tools/lib/bpf/libbpf.c | 3 + tools/lib/bpf/libbpf_probes.c | 2 + 16 files changed, 514 insertions(+) create mode 100644 include/linux/bpf_oom.h create mode 100644 samples/bpf/oom_kern.c create mode 100644 samples/bpf/oom_user.c