From patchwork Fri Jun 19 16:23:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 11614631 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A476414B7 for ; Fri, 19 Jun 2020 16:25:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7203E2067D for ; Fri, 19 Jun 2020 16:25:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7203E2067D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 19EEF8D00E2; Fri, 19 Jun 2020 12:24:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 14ECB8D00E1; Fri, 19 Jun 2020 12:24:44 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04AAB8D00E2; Fri, 19 Jun 2020 12:24:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0170.hostedemail.com [216.40.44.170]) by kanga.kvack.org (Postfix) with ESMTP id DB13B8D00E1 for ; Fri, 19 Jun 2020 12:24:43 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9C172181ACC80 for ; Fri, 19 Jun 2020 16:24:43 +0000 (UTC) X-FDA: 76946484846.07.name73_240f38126e1a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 7240D1803F9A1 for ; Fri, 19 Jun 2020 16:24:43 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,ben.widawsky@intel.com,,RULES_HIT:30012:30036:30054:30064:30091,0,RBL:192.55.52.120:@intel.com:.lbl8.mailshell.net-64.95.201.95 62.50.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:22,LUA_SUMMARY:none X-HE-Tag: name73_240f38126e1a X-Filterd-Recvd-Size: 7559 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Fri, 19 Jun 2020 16:24:42 +0000 (UTC) IronPort-SDR: QVWAXQYwTFdHrKYDbX68naTp8/bJuIXd6znQzz2j9MsKhsLJc4scquwYbBt6IOcDL7dPJTAMyW b+qy8Orrz22A== X-IronPort-AV: E=McAfee;i="6000,8403,9657"; a="140535473" X-IronPort-AV: E=Sophos;i="5.75,256,1589266800"; d="scan'208";a="140535473" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2020 09:24:15 -0700 IronPort-SDR: Pcysprfmhil2hCgFJIU5yLf5/JukB5iGHcMHS5Eq/5+6gUuGGysTMRRK/ijY/8RChd7weuQeXy Ti41iwjzewOA== X-IronPort-AV: E=Sophos;i="5.75,255,1589266800"; d="scan'208";a="264366188" Received: from sjiang-mobl2.ccr.corp.intel.com (HELO bwidawsk-mobl5.local) ([10.252.131.131]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jun 2020 09:24:15 -0700 From: Ben Widawsky To: linux-mm Subject: [PATCH 00/18] multiple preferred nodes Date: Fri, 19 Jun 2020 09:23:56 -0700 Message-Id: <20200619162414.1052234-1-ben.widawsky@intel.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 7240D1803F9A1 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: This patch series introduces the concept of the MPOL_PREFERRED_MANY mempolicy. This mempolicy mode can be used with either the set_mempolicy(2) or mbind(2) interfaces. Like the MPOL_PREFERRED interface, it allows an application to set a preference for nodes which will fulfil memory allocation requests. Like the MPOL_BIND interface, it works over a set of nodes. Summary: 1-2: Random fixes I found along the way 3-4: Logic to handle many preferred nodes in page allocation 5-9: Plumbing to allow multiple preferred nodes in mempolicy 10-13: Teach page allocation APIs about nodemasks 14: Provide a helper to generate preferred nodemasks 15: Have page allocation callers generate preferred nodemasks 16-17: Flip the switch to have __alloc_pages_nodemask take preferred mask. 18: Expose the new uapi Along with these patches are patches for libnuma, numactl, numademo, and memhog. They still need some polish, but can be found here: https://gitlab.com/bwidawsk/numactl/-/tree/prefer-many It allows new usage: `numactl -P 0,3,4` The goal of the new mode is to enable some use-cases when using tiered memory usage models which I've lovingly named. 1a. The Hare - The interconnect is fast enough to meet bandwidth and latency requirements allowing preference to be given to all nodes with "fast" memory. 1b. The Indiscriminate Hare - An application knows it wants fast memory (or perhaps slow memory), but doesn't care which node it runs on. The application can prefer a set of nodes and then xpu bind to the local node (cpu, accelerator, etc). This reverses the nodes are chosen today where the kernel attempts to use local memory to the CPU whenever possible. This will attempt to use the local accelerator to the memory. 2. The Tortoise - The administrator (or the application itself) is aware it only needs slow memory, and so can prefer that. Much of this is almost achievable with the bind interface, but the bind interface suffers from an inability to fallback to another set of nodes if binding fails to all nodes in the nodemask. Like MPOL_BIND a nodemask is given. Inherently this removes ordering from the preference. > /* Set first two nodes as preferred in an 8 node system. */ > const unsigned long nodes = 0x3 > set_mempolicy(MPOL_PREFER_MANY, &nodes, 8); > /* Mimic interleave policy, but have fallback *. > const unsigned long nodes = 0xaa > set_mempolicy(MPOL_PREFER_MANY, &nodes, 8); Some internal discussion took place around the interface. There are two alternatives which we have discussed, plus one I stuck in: 1. Ordered list of nodes. Currently it's believed that the added complexity is nod needed for expected usecases. 2. A flag for bind to allow falling back to other nodes. This confuses the notion of binding and is less flexible than the current solution. 3. Create flags or new modes that helps with some ordering. This offers both a friendlier API as well as a solution for more customized usage. It's unknown if it's worth the complexity to support this. Here is sample code for how this might work: > // Default > set_mempolicy(MPOL_PREFER_MANY | MPOL_F_PREFER_ORDER_SOCKET, NULL, 0); > // which is the same as > set_mempolicy(MPOL_DEFAULT, NULL, 0); > > // The Hare > set_mempolicy(MPOL_PREFER_MANY | MPOL_F_PREFER_ORDER_TYPE, NULL, 0); > > // The Tortoise > set_mempolicy(MPOL_PREFER_MANY | MPOL_F_PREFER_ORDER_TYPE_REV, NULL, 0); > > // Prefer the fast memory of the first two sockets > set_mempolicy(MPOL_PREFER_MANY | MPOL_F_PREFER_ORDER_TYPE, -1, 2); > > // Prefer specific nodes for some something wacky > set_mempolicy(MPOL_PREFER_MANY | MPOL_F_PREFER_ORDER_TYPE_CUSTOM, 0x17c, 1024); --- Cc: Andi Kleen Cc: Andrew Morton Cc: Christoph Lameter Cc: Dan Williams Cc: Dave Hansen Cc: David Hildenbrand Cc: David Rientjes Cc: Jason Gunthorpe Cc: Johannes Weiner Cc: Jonathan Corbet Cc: Kuppuswamy Sathyanarayanan Cc: Lee Schermerhorn Cc: Li Xinhai Cc: Mel Gorman Cc: Michal Hocko Cc: Mike Kravetz Cc: Mina Almasry Cc: Tejun Heo Cc: Vlastimil Babka Ben Widawsky (14): mm/mempolicy: Add comment for missing LOCAL mm/mempolicy: Use node_mem_id() instead of node_id() mm/page_alloc: start plumbing multi preferred node mm/page_alloc: add preferred pass to page allocation mm: Finish handling MPOL_PREFERRED_MANY mm: clean up alloc_pages_vma (thp) mm: Extract THP hugepage allocation mm/mempolicy: Use __alloc_page_node for interleaved mm: kill __alloc_pages mm/mempolicy: Introduce policy_preferred_nodes() mm: convert callers of __alloc_pages_nodemask to pmask alloc_pages_nodemask: turn preferred nid into a nodemask mm: Use less stack for page allocations mm/mempolicy: Advertise new MPOL_PREFERRED_MANY Dave Hansen (4): mm/mempolicy: convert single preferred_node to full nodemask mm/mempolicy: Add MPOL_PREFERRED_MANY for multiple preferred nodes mm/mempolicy: allow preferred code to take a nodemask mm/mempolicy: refactor rebind code for PREFERRED_MANY .../admin-guide/mm/numa_memory_policy.rst | 22 +- include/linux/gfp.h | 19 +- include/linux/mempolicy.h | 4 +- include/linux/migrate.h | 4 +- include/linux/mmzone.h | 3 + include/uapi/linux/mempolicy.h | 6 +- mm/hugetlb.c | 10 +- mm/internal.h | 1 + mm/mempolicy.c | 271 +++++++++++++----- mm/page_alloc.c | 179 +++++++++++- 10 files changed, 403 insertions(+), 116 deletions(-)