Received: by 10.223.185.116 with SMTP id b49csp290757wrg; Thu, 15 Feb 2018 22:05:17 -0800 (PST) X-Google-Smtp-Source: AH8x225XC3fheiFLFYiYUV9iB5klFPXwPs/6uteG17rkxlaIBEFNyB8zVKqh/ub35VaLlgw84qcW X-Received: by 10.98.79.194 with SMTP id f63mr5026269pfj.28.1518761117459; Thu, 15 Feb 2018 22:05:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518761117; cv=none; d=google.com; s=arc-20160816; b=ZzQQPPw4tzYFsQrDVkeKk8U3QW9uatGGw8MTZebBCBEmuUjw+yl9Il5T0cAm8Ps2Dz /ml0InLS8AIipKF2jH4Ze8wL7+WpI+rKAKTMwvJAka/rw7ejUSCsg0vvfePVPZhWgsAz 9BAhrodaPDNcQkkQXOpO5pcDu/sBUxGk/ihJdRzrUqzRdC1TlDrdy0LpiApZkMo62wXF CKZ2aXiWFd8qXAjFuMxAciFyZAmAZbZ9Zjvnfy/ozzKZM2Uc4RcmHmyV89QzoEHD+rnQ KGjvNtpuWNT8XyWda6AFBUDmIcIUORyPTd9VN5mAQ9CEz45vlL9qR3Hr9bdPjZgWnJ3b TdMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=mZiAZMNpG9lAPGCgchqLbzz22t3wjUodIbEb3pDIAxI=; b=q6YQrKv+fjAF1Ab/MffLx37wZGJdr6NWpNecKf03rpi1h5NoAIsGoozwjL1sE3JLfM XsYu2RboRlplH8OrSnX1RhrxaoG/W38HKf9jcRrnOUyxsPKgw8EfosPKBOgZ4Kh5I9VS oqQPht/ZvHHwMXV/izm8121un8T8y1RjcJCyI79JkrnhNPEjDKF+QAkBZ7KZQ13yb9eT 5dYAJQ/xzVM066q8ujaZD5UNXJtesOImM76W+0GCFFyWDQ42VvCv11+XDeMFCLYXgdLH 79xsSvk9g88y5wD5NbB+qjv6+wBlonP6/T8xogF3+T6np6Qg9/tAm6SMiCrL5M+Onb2V yJUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XjTm4DS7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g11si3582599pgo.717.2018.02.15.22.05.02; Thu, 15 Feb 2018 22:05:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XjTm4DS7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1425596AbeBOQJO (ORCPT + 99 others); Thu, 15 Feb 2018 11:09:14 -0500 Received: from mail-it0-f51.google.com ([209.85.214.51]:36535 "EHLO mail-it0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424566AbeBOQJJ (ORCPT ); Thu, 15 Feb 2018 11:09:09 -0500 Received: by mail-it0-f51.google.com with SMTP id 18so1176506itj.1 for ; Thu, 15 Feb 2018 08:09:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=mZiAZMNpG9lAPGCgchqLbzz22t3wjUodIbEb3pDIAxI=; b=XjTm4DS7b8OEEecKx03h7PsVoeauBkeQ8aywPVKa6ZmM5XCwYf/bv1lLe//9C9UVRb heKRtRWxwVuOsAcm5MucEfbX9PS0zK9GlZvgtS2BQ9+b8MNGmONdaiHkLdKEq7+uf3hC 6Lb6NLlHbxTEFk2nIqwWcxG3wp++CYAET2EysioNa5CUJB3nLB1tltLzRrBIk42vDxQF HGoMBrNIHPGgzNZQh2mKIsNfkOhfFrOEBX1PAhe5proitNy/rAJWLSf0yBqlnB9AbfV2 bD3BBCi00zoo1Xj9JH6igt3lUV0198T9OSICGVZWCsOTfY4MRExrG8h4S0rUc0SRf/is vMrA== 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:in-reply-to:references; bh=mZiAZMNpG9lAPGCgchqLbzz22t3wjUodIbEb3pDIAxI=; b=baO8jY1SbSf0QQ7sFjZ281a5+PchQhCzvAKSF5nWdDaR4RfABAV0qf7nrC7xN8vmbz i93YMCqGV7KaD+M59v4GrG4LKPIes0wBlEPto+6wQoqNb2c6OILIIJmp3KsPIR4HZ2GL +to2Mx1k5T51ItDdCsUdQan/SQEiZAMpFZLcFZtS07J+Y77H3WUnltt1HDcgwnfL1QSB Kip9PgD9QGeL+PM2I3y7WYGU8389rOX29BT2VvUEQHsIM/byUgBqpVnHPqKc23AS/xfn fbWKgTzb0EMLiaSzRsqBXh+rEy4pTQvxBgvO12aPQShvj+9WjaxfJ6K0pDrJMEZ6z5s6 pCmQ== X-Gm-Message-State: APf1xPC/VfWLHpT91/sWi3Jq7GqHL4lJbAanj6r5NXoCLt99EOYTMONV ueNMdJkPn/y9AJVLOv20WVI= X-Received: by 10.36.108.19 with SMTP id w19mr4046519itb.65.1518710948372; Thu, 15 Feb 2018 08:09:08 -0800 (PST) Received: from localhost.attlocal.net (104-187-157-211.lightspeed.mdsnwi.sbcglobal.net. [104.187.157.211]) by smtp.gmail.com with ESMTPSA id l5sm1689313itl.7.2018.02.15.08.09.07 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 15 Feb 2018 08:09:07 -0800 (PST) From: Dennis Zhou To: Tejun Heo , Christoph Lameter Cc: Daniel Borkmann , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dennis Zhou Subject: [PATCH 3/3] percpu: allow select gfp to be passed to underlying allocators Date: Thu, 15 Feb 2018 10:08:16 -0600 Message-Id: X-Mailer: git-send-email 1.8.5.2 (Apple Git-48) In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The prior patch added support for passing gfp flags through to the underlying allocators. This patch allows users to pass along gfp flags (currently only __GFP_NORETRY and __GFP_NOWARN) to the underlying allocators. This should allow users to decide if they are ok with failing allocations recovering in a more graceful way. Additionally, the prior use of gfp was as additional gfp flags that were then combined with the base flags, namely GFP_KERNEL. gfp_percpu_mask is introduced to create the base of GFP_KERNEL and whitelist allowed gfp flags. Using this in the appropriate places changes gfp use from as additional flags to as a whole set in general removing the need to always or with the GFP_KERNEL. Signed-off-by: Dennis Zhou Suggested-by: Daniel Borkmann --- mm/percpu-km.c | 2 +- mm/percpu-vm.c | 4 ++-- mm/percpu.c | 16 ++++++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/mm/percpu-km.c b/mm/percpu-km.c index 0d88d7b..38de70a 100644 --- a/mm/percpu-km.c +++ b/mm/percpu-km.c @@ -56,7 +56,7 @@ static struct pcpu_chunk *pcpu_create_chunk(gfp_t gfp) if (!chunk) return NULL; - pages = alloc_pages(gfp | GFP_KERNEL, order_base_2(nr_pages)); + pages = alloc_pages(gfp, order_base_2(nr_pages)); if (!pages) { pcpu_free_chunk(chunk); return NULL; diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c index ea9906a..c771d86 100644 --- a/mm/percpu-vm.c +++ b/mm/percpu-vm.c @@ -37,7 +37,7 @@ static struct page **pcpu_get_pages(void) lockdep_assert_held(&pcpu_alloc_mutex); if (!pages) - pages = pcpu_mem_zalloc(pages_size, 0); + pages = pcpu_mem_zalloc(pages_size, gfp_percpu_mask(0)); return pages; } @@ -86,7 +86,7 @@ static int pcpu_alloc_pages(struct pcpu_chunk *chunk, unsigned int cpu, tcpu; int i; - gfp |= GFP_KERNEL | __GFP_HIGHMEM; + gfp |= __GFP_HIGHMEM; for_each_possible_cpu(cpu) { for (i = page_start; i < page_end; i++) { diff --git a/mm/percpu.c b/mm/percpu.c index 2489b8b..e35a120 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -91,6 +91,10 @@ #include "percpu-internal.h" +/* the whitelisted flags that can be passed to the backing allocators */ +#define gfp_percpu_mask(gfp) (((gfp) & (__GFP_NORETRY | __GFP_NOWARN)) | \ + GFP_KERNEL) + /* the slots are sorted by free bytes left, 1-31 bytes share the same slot */ #define PCPU_SLOT_BASE_SHIFT 5 @@ -466,10 +470,9 @@ static void *pcpu_mem_zalloc(size_t size, gfp_t gfp) return NULL; if (size <= PAGE_SIZE) - return kzalloc(size, gfp | GFP_KERNEL); + return kzalloc(size, gfp); else - return __vmalloc(size, gfp | GFP_KERNEL | __GFP_ZERO, - PAGE_KERNEL); + return __vmalloc(size, gfp | __GFP_ZERO, PAGE_KERNEL); } /** @@ -1344,6 +1347,7 @@ static struct pcpu_chunk *pcpu_chunk_addr_search(void *addr) static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, gfp_t gfp) { + gfp_t pcpu_gfp = gfp_percpu_mask(gfp); bool is_atomic = (gfp & GFP_KERNEL) != GFP_KERNEL; bool do_warn = !(gfp & __GFP_NOWARN); static int warn_limit = 10; @@ -1426,7 +1430,7 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, } if (list_empty(&pcpu_slot[pcpu_nr_slots - 1])) { - chunk = pcpu_create_chunk(0); + chunk = pcpu_create_chunk(pcpu_gfp); if (!chunk) { err = "failed to allocate new chunk"; goto fail; @@ -1455,7 +1459,7 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, page_start, page_end) { WARN_ON(chunk->immutable); - ret = pcpu_populate_chunk(chunk, rs, re, 0); + ret = pcpu_populate_chunk(chunk, rs, re, pcpu_gfp); spin_lock_irqsave(&pcpu_lock, flags); if (ret) { @@ -1576,7 +1580,7 @@ void __percpu *__alloc_reserved_percpu(size_t size, size_t align) static void pcpu_balance_workfn(struct work_struct *work) { /* gfp flags passed to underlying allocators */ - gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN; + gfp_t gfp = gfp_percpu_mask(__GFP_NORETRY | __GFP_NOWARN); LIST_HEAD(to_free); struct list_head *free_head = &pcpu_slot[pcpu_nr_slots - 1]; struct pcpu_chunk *chunk, *next; -- 1.8.3.1