From patchwork Fri Apr 14 00:11:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 83144 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp26869vqo; Thu, 13 Apr 2023 17:13:31 -0700 (PDT) X-Google-Smtp-Source: AKy350aj2ksg0/xlaF4fLubP6+TUPuRjT2559HSgCifei/eE2t933Nvf43AAqWXpWaRJmfwvt9eU X-Received: by 2002:a17:902:e811:b0:1a5:898:37aa with SMTP id u17-20020a170902e81100b001a5089837aamr992732plg.15.1681431210836; Thu, 13 Apr 2023 17:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681431210; cv=none; d=google.com; s=arc-20160816; b=NefIALjEv1qjK8tyytIE9/kWEx9egtvOeJQqS32OPQkLto1XLFVGVNvUqyG5+cUHls RIvjakIS3swZ73b0w9+QFyQPz237EF6n/RdMCgDcPhlHeUhCzjRkXhBOObdmszzOoqsH M6IV5D66fzGEtqY0CykRDsV4gyDALvK6KWlFTfaFsrTIOIzSjr2zvpltHAfhV/v+Ehvj UK7hTDMC36hknPtpALqhVGxMJ55HIFgM+Xcz93XXgCxhK+QpnBo8Um44vfy+WbdpyWCa 53YmJM95SIanH3D6A1nsq8Fg/mucx80B+l3m+FCJ1Jx9quhCC5RipEJW3Qeq2UMAN3Hk f4eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Gsr9n7GPJt3nQiq4GcQ+TdB+rTZDJHWVuXMgSAc/inc=; b=fNig/aOCcQ8y0+5DSVGyAqKEB1oCjlKnUurjjErKo9QmXXFiAe0QcrGBlFaLGifUnz RtMTDJzD+1dGI1UJvuqeuYGgbfESCGlmb1Cf08IRDsDChkToUmFzlvoWtFcTnzpLM9UY eQLLCXEsocsrRBf57bUx8mguOsRfzZW5sdE6ATQ7jZ9ZmD0d1pXovzsv62gbz79XvtAL IHx2V7DN5FFp1VFW7nfEMBkCI7IX8BLtIOegFxXnh5Qodj5DEwMZa78sTYyidQDFZzij 392ltiLHjb4O8wyvbrWYT7WLpL39zOn69D5mmUj2IlDqPe8HlMhTRXR0PoR31anNmO29 HekA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=kiDTePLk; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b10-20020a170902d50a00b001a647aadbeasi3429321plg.416.2023.04.13.17.13.17; Thu, 13 Apr 2023 17:13:30 -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=@google.com header.s=20221208 header.b=kiDTePLk; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231143AbjDNAMW (ORCPT + 99 others); Thu, 13 Apr 2023 20:12:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230271AbjDNAMG (ORCPT ); Thu, 13 Apr 2023 20:12:06 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9C723A86 for ; Thu, 13 Apr 2023 17:12:04 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54ee397553eso171355807b3.19 for ; Thu, 13 Apr 2023 17:12:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681431124; x=1684023124; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Gsr9n7GPJt3nQiq4GcQ+TdB+rTZDJHWVuXMgSAc/inc=; b=kiDTePLk95tLtwi05EOCo6F4V5CaUODRfRqdJI4Zgzm9FQWvaGZtlrD6yXaeMKkBjy 8RYIMMqxVwtK8hcqiFL4L6XAaUQuBxXj0Ob3OL8FosXLKFkReuzMoaSCAc6uSho3g0AT 1Mad+18Vu1ODUbN+2p4Gx7UN/JCMROb9IKSQZwVC0SqUcslnNIKVGAjm6jXtAj4CVyW6 AubdJjVqBGvAcIQftDMGLDBeWf29B2Tvkh+iboimGU/GxdHwLZqBuIds+tebPgdOIXna fQ+8mzrH61gD5Hs3hKsbNr1LXybHaYbyOLpWo62wPHciL4cbfv9pbXLpD+tC0w5oX1yN Vaaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681431124; x=1684023124; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Gsr9n7GPJt3nQiq4GcQ+TdB+rTZDJHWVuXMgSAc/inc=; b=TZj7THnJtuo56a/VKISAeDArM96V6uO8XL4aRmUdTtWYF2jt72xHmHB/cMySIu7nDp /MrVCjZo+LWlxEfCX6qP8bERHRX4E44XFe9EFvQV7T3tb6PJq9nDX5CEHqclvTm8eABt Ze7+iQn/VU4Ob+T5XnYp8DuOuk0RAuemFF8A+0XnrvtRxGe0E9MkRx9HFpa6DlJn3QQ5 84+YfpQiQYYddDfBMOJjnI8kUVeHwMRUjFfRvQsvkOX/MF4eQQpgM6u2W0CaXSAVgpTN BiKP0ljsJik1iPozfzzlGgrowNUa8fswu9izL+DtCYwN9oFHBB/asSSoeXjt9VnnJp+e ae9Q== X-Gm-Message-State: AAQBX9cxvJ1FEIUDOKrapRrSnwN0eVK92agBBwb8adDHi97IlBIvdtLX 18SNH4wENbYFQNVvYQpr0G6gOaSH8dvt5jpxJw== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a81:af0c:0:b0:54f:8566:495 with SMTP id n12-20020a81af0c000000b0054f85660495mr2640217ywh.1.1681431123807; Thu, 13 Apr 2023 17:12:03 -0700 (PDT) Date: Fri, 14 Apr 2023 00:11:52 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <43e1c951125d6700586dbd332c2036db0f2f5f2d.1681430907.git.ackerleytng@google.com> Subject: [RFC PATCH 3/6] mm: mempolicy: Refactor out __mpol_set_shared_policy() From: Ackerley Tng To: kvm@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, qemu-devel@nongnu.org Cc: aarcange@redhat.com, ak@linux.intel.com, akpm@linux-foundation.org, arnd@arndb.de, bfields@fieldses.org, bp@alien8.de, chao.p.peng@linux.intel.com, corbet@lwn.net, dave.hansen@intel.com, david@redhat.com, ddutile@redhat.com, dhildenb@redhat.com, hpa@zytor.com, hughd@google.com, jlayton@kernel.org, jmattson@google.com, joro@8bytes.org, jun.nakajima@intel.com, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, luto@kernel.org, mail@maciej.szmigiero.name, mhocko@suse.com, michael.roth@amd.com, mingo@redhat.com, naoya.horiguchi@nec.com, pbonzini@redhat.com, qperret@google.com, rppt@kernel.org, seanjc@google.com, shuah@kernel.org, steven.price@arm.com, tabba@google.com, tglx@linutronix.de, vannapurve@google.com, vbabka@suse.cz, vkuznets@redhat.com, wanpengli@tencent.com, wei.w.wang@intel.com, x86@kernel.org, yu.c.zhang@linux.intel.com, muchun.song@linux.dev, feng.tang@intel.com, brgerst@gmail.com, rdunlap@infradead.org, masahiroy@kernel.org, mailhol.vincent@wanadoo.fr, Ackerley Tng X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763108413461177727?= X-GMAIL-MSGID: =?utf-8?q?1763108413461177727?= Refactor out __mpol_set_shared_policy() to remove dependency on struct vm_area_struct, since only 2 parameters from struct vm_area_struct are used. __mpol_set_shared_policy() will be used in a later patch by restrictedmem_set_shared_policy(). Signed-off-by: Ackerley Tng --- include/linux/mempolicy.h | 2 ++ mm/mempolicy.c | 29 +++++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h index d232de7cdc56..9a2a2dd95432 100644 --- a/include/linux/mempolicy.h +++ b/include/linux/mempolicy.h @@ -126,6 +126,8 @@ struct shared_policy { int vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst); void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol); +int __mpol_set_shared_policy(struct shared_policy *info, struct mempolicy *mpol, + unsigned long pgoff_start, unsigned long npages); int mpol_set_shared_policy(struct shared_policy *info, struct vm_area_struct *vma, struct mempolicy *new); diff --git a/mm/mempolicy.c b/mm/mempolicy.c index a2655b626731..f3fa5494e4a8 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2817,30 +2817,39 @@ void mpol_shared_policy_init(struct shared_policy *sp, struct mempolicy *mpol) } } -int mpol_set_shared_policy(struct shared_policy *info, - struct vm_area_struct *vma, struct mempolicy *npol) +int __mpol_set_shared_policy(struct shared_policy *info, struct mempolicy *mpol, + unsigned long pgoff_start, unsigned long npages) { int err; struct sp_node *new = NULL; - unsigned long sz = vma_pages(vma); + unsigned long pgoff_end = pgoff_start + npages; pr_debug("set_shared_policy %lx sz %lu %d %d %lx\n", - vma->vm_pgoff, - sz, npol ? npol->mode : -1, - npol ? npol->flags : -1, - npol ? nodes_addr(npol->nodes)[0] : NUMA_NO_NODE); + pgoff_start, npages, + mpol ? mpol->mode : -1, + mpol ? mpol->flags : -1, + mpol ? nodes_addr(mpol->nodes)[0] : NUMA_NO_NODE); - if (npol) { - new = sp_alloc(vma->vm_pgoff, vma->vm_pgoff + sz, npol); + if (mpol) { + new = sp_alloc(pgoff_start, pgoff_end, mpol); if (!new) return -ENOMEM; } - err = shared_policy_replace(info, vma->vm_pgoff, vma->vm_pgoff+sz, new); + + err = shared_policy_replace(info, pgoff_start, pgoff_end, new); + if (err && new) sp_free(new); + return err; } +int mpol_set_shared_policy(struct shared_policy *info, + struct vm_area_struct *vma, struct mempolicy *mpol) +{ + return __mpol_set_shared_policy(info, mpol, vma->vm_pgoff, vma_pages(vma)); +} + /* Free a backing policy store on inode delete. */ void mpol_free_shared_policy(struct shared_policy *p) {