From patchwork Thu Apr 22 09:06:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abel Wu X-Patchwork-Id: 12218033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0B06C433B4 for ; Thu, 22 Apr 2021 09:06:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1683F61459 for ; Thu, 22 Apr 2021 09:06:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1683F61459 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9663F6B0073; Thu, 22 Apr 2021 05:06:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9164A6B0074; Thu, 22 Apr 2021 05:06:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 741D56B0075; Thu, 22 Apr 2021 05:06:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 53CD26B0073 for ; Thu, 22 Apr 2021 05:06:19 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EB54C5923C1A for ; Thu, 22 Apr 2021 09:06:18 +0000 (UTC) X-FDA: 78059421636.22.E201279 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf10.hostedemail.com (Postfix) with ESMTP id 930A540002D0 for ; Thu, 22 Apr 2021 09:06:10 +0000 (UTC) Received: by mail-pl1-f170.google.com with SMTP id y1so7547014plg.11 for ; Thu, 22 Apr 2021 02:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZTf4VDhB+vsAlWiKaTvh+bcNfZdV5PiIE39ZO2UyLSc=; b=QKA0xpPzIE5m7ObGgIH4Ww862+GJtKlZgxONOym/4benb+hChVs1lThp8lwEvL6DZx gS1BnKHW2MgjI3Lqh5503JGP4B0YVGJFdTsikNoUyTXVN116heU7bqRphUrvPGj92oKd +u5PUlbGn7/JrtSL9OtxLTP32nBbFwhlhOx4HU414jrOF5HheHVeODie6K4UMF1xs22x 1CBrFHKGf5P2fQHjAKP1nUFeiSwN9yC7eLv+/vTZUzLUSaD2Hd9Io2IVjr+e60skyXih 6kNpW9gEiD1qkbAycdjVN/M0wr2e+UqQWumISWzgQUrI+Hf7bbUsUK9udCeOsfxOK0LO WP/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZTf4VDhB+vsAlWiKaTvh+bcNfZdV5PiIE39ZO2UyLSc=; b=Rskdka7PKTTZZcVGAw4rK9Tso2my9srNZZdB8Q2DIMEXMbxq5wSxKk0lgyq1uIezBU 6sLQSuNtW2sfh0M8OpZdqs7ad2olZ5xjUoj1dp8m/qe/OtzaoPsfpwWuK4fspd/NzvDG gJKRB+rWdUt38rL/xsLHJWc0AnjD7X4r7F2vliLm/Qpl7kMmX/DhOxB41FcrsTcWwP0i V8L1EsOtsvBhVvA1/wQ8FpU7LFtQZAbVXxmkgvj1mh/yCvHOxPivZ6yWopuCQ//1Pgu5 +gdF18PZQXDuv8MxW7T5x/vGrqN7nLARfKDeIuF4OProkS4qnPEi0TctloFfoFPJa+DZ 1tcw== X-Gm-Message-State: AOAM532NgeFk2DPv9M9tim1TosWUDuAinIs8aEXhtnoohmVLeQOmylIk /slmzd0jj/ykqK5TbN73rXFMTQ== X-Google-Smtp-Source: ABdhPJy7hDjm/CvB0p5qTi+Hnk4OrdeiYrBuA5gdl7Zxb1Pv4C2IC+AbA17XxgO/+j11iunrSnKAAA== X-Received: by 2002:a17:90a:4290:: with SMTP id p16mr16316343pjg.120.1619082377567; Thu, 22 Apr 2021 02:06:17 -0700 (PDT) Received: from C02DV8HUMD6R.bytedance.net ([139.177.225.240]) by smtp.gmail.com with ESMTPSA id x2sm1514348pfu.77.2021.04.22.02.06.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Apr 2021 02:06:17 -0700 (PDT) From: Abel Wu To: akpm@linux-foundation.org, lizefan.x@bytedance.com, tj@kernel.org, hannes@cmpxchg.org, corbet@lwn.net Cc: cgroups@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/3] mm/mempolicy: apply cpuset limits to tasks using default policy Date: Thu, 22 Apr 2021 17:06:06 +0800 Message-Id: <20210422090608.7160-2-wuyun.abel@bytedance.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210422090608.7160-1-wuyun.abel@bytedance.com> References: <20210422090608.7160-1-wuyun.abel@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 930A540002D0 X-Stat-Signature: 6hy85uuyt9yyc8b6h3ffux15o31zhkxb X-Rspamd-Server: rspam02 Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=mail-pl1-f170.google.com; client-ip=209.85.214.170 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619082370-50733 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The nodemasks of non-default policies (pol->v) are calculated within the restriction of task->mems_allowed, while default policies are not. This may lead to improper results of mpol_misplaced(), since it can return a target node outside of current->mems_allowed for tasks using default policies. Although this is not a bug because migrating pages to that out-of-cpuset node will fail eventually due to sanity checks in page allocation, it still would be better to avoid such useless efforts. This patch also changes the behavior of autoNUMA a bit by showing a tendency to move pages inside mems_allowed for tasks using default policies, which is good for memory isolation. Signed-off-by: Abel Wu --- mm/mempolicy.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index d79fa299b70c..e0ae6997bbfb 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2516,7 +2516,10 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long /* Migrate the page towards the node whose CPU is referencing it */ if (pol->flags & MPOL_F_MORON) { - polnid = thisnid; + if (node_isset(thisnid, cpuset_current_mems_allowed)) + polnid = thisnid; + else + polnid = node_random(&cpuset_current_mems_allowed); if (!should_numa_migrate_memory(current, page, curnid, thiscpu)) goto out;