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: 13210786 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF4AFC77B7E for ; Fri, 14 Apr 2023 00:12:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1F306B007B; Thu, 13 Apr 2023 20:12:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA7756B007D; Thu, 13 Apr 2023 20:12:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD37E900002; Thu, 13 Apr 2023 20:12:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A98306B007B for ; Thu, 13 Apr 2023 20:12:06 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6706E1604EB for ; Fri, 14 Apr 2023 00:12:06 +0000 (UTC) X-FDA: 80678069052.06.3886E48 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf24.hostedemail.com (Postfix) with ESMTP id A489B18000D for ; Fri, 14 Apr 2023 00:12:04 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=kiDTePLk; spf=pass (imf24.hostedemail.com: domain of 3U5o4ZAsKCJIwy60D70KF922AA270.yA8749GJ-886Hwy6.AD2@flex--ackerleytng.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3U5o4ZAsKCJIwy60D70KF922AA270.yA8749GJ-886Hwy6.AD2@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681431124; a=rsa-sha256; cv=none; b=Q8S9RgN2LJ8FNAtF3g3b5YjIa+ctNVptjJyvsxso4F0zS4DiR4N469aQKrLUJLC5WGe4CC CkWR7+byaob8WnVY09pIeUSrO3rkK0k19vZ3DTOIKFc+UV0tNWcM48FBsreJutSD+kblQ1 RW/6YLptUcvkbzHEfhOuKLk0FaySnq4= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=kiDTePLk; spf=pass (imf24.hostedemail.com: domain of 3U5o4ZAsKCJIwy60D70KF922AA270.yA8749GJ-886Hwy6.AD2@flex--ackerleytng.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3U5o4ZAsKCJIwy60D70KF922AA270.yA8749GJ-886Hwy6.AD2@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681431124; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Gsr9n7GPJt3nQiq4GcQ+TdB+rTZDJHWVuXMgSAc/inc=; b=oDWV5elwJlT9TlfuxoUhR5iyrSFYLpPy64GiMWoQQrLaPaF1VFCX7x2xFXC/fAFg8Tt7GG XojG6lf+vLJZYH8cnra8+RdYD9lHfodvRQZS0NyqNV6Q3D58xnbJWPmU51CMSDJIyV9PcI g1sq0rpTDKvfvqWxTkrl6gIz0C8FP9c= Received: by mail-yb1-f202.google.com with SMTP id 132-20020a250c8a000000b00b8f4e12dd57so5572387ybm.1 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=bEBRyKwhzHjISa9kEbaiDkyRB4Es5QSUE0NQudNr5IWONFOinQ/ncS29kvH5RyZbm7 Q3M0wRT1vUxyfg8Nvvyorxf6ZAT8egOw6XkqhbTKDrH7Mc+HLTv+k4qWD/rVceOpsqdg 88ySUtKis9xBZ57QPliKKQ4ecwFSleVYDumfjCrlPjcC2biPvbD8/pOYxG9RoF8QxpTT K3vLxWe1c8J1AJhVjWLXR19G4/d65UaLq/nNDjUWAGotIxciYtsXnNQUBHOtE6o0cHIB xfSrXvJGpO/jWcpggQdxdQwefd6vNchBWXiNzkTSQ0lcLF1LIe8fqcz6TKe91rgmQrmH /i4g== X-Gm-Message-State: AAQBX9eL8zDOtrvkUAVgOCwFd2tmeZ4j/1HzkoWFDiewsBuPHBRbPXGM P38q9+jeCCHTK6DNeDD1ELGHNy9EgYAvWBazMQ== X-Google-Smtp-Source: AKy350aRre2/mW24vntSSS5eHQnqj/lI3imd9ledXWOeS14bBFvJmCzkihwUza6OXJc/lSYwICNxvky6ENjOvWGfVA== 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-Rspam-User: X-Rspamd-Queue-Id: A489B18000D X-Rspamd-Server: rspam01 X-Stat-Signature: 98ccgwacet73k6n7u9ropyu8mjabmgng X-HE-Tag: 1681431124-532604 X-HE-Meta: U2FsdGVkX1+YK6nDxZuULyUme2dPygtV474j4UO7/wdMAwi+nQBMJEA7p9LnxnK/XtertqqNZ+XvviruSUbm34eFdxCUFiLTvwyrNZseJK2khxNy/m/20vvy/vv+LYoAeOWIxd546Zi6I04YTrLKuoLKgE2DPnVbBVANxMeBqa2f21ERSNFIco0yGJZpFP52Zc8quTHBG3RXqbGTkA2j412tkqxSvdw2O6QuV08sKDd+Vk0G3ON97TMYYPjzQ+Z6matK30m1Ddvx1mgXTOaXIijLOLk5KUX8z6ynPJCxxyrqNpNuH01Q3EeFuAiGyVMY9u8CYgtGV2+rDktWRsb4oqe3Fz/1iL+ORc/6t6jMXim07FWfvXEmcBTw0RLdMi7AshUk3LnCh+S4D7DMnZX8doTCJpe95EznU+R2i+IdFcrqp4mBtPoPNv1HRBlje87Zz0TuLwSkYObKSkrEJKF6NLbxonrMJk4/MFVvuvXtM/JG44USfXOVveCNuGB2mSp9rBcfGlDUzwrVZS+mpH8E93/dDUvcPdhCzb7FkXo6W/2HrO+PUgeQeW+SFI+ZSBYAjWIOFtr1QNOJIJlh/xIPOAIX9RNlzQiHZJkP2RdIqXFYuLbYbwbSWDZSFoASeFHl1MZgVIL+FxGOjwtEmtGTt2KVvSqE2djh9vQWBe7CP/k9LNoAgfAIno9qzSKvSYezPst8L9kyOyPnqJcs9I5zXBcFdM9rIqObMlZeiELByMNWQJOaPVceEqAJIHv0x4/D1Omug7QOkAdFoNRRAKKEQbJm9/j/0l4AFKobYL3Cem5ytaVyZe6XZrGul+bx+C/6Z2PjLhr/dAIk7rnSOLZ4DJElHjIri5SPaG96E8ccqRWPOUq2WxGQLRRzxgCJLGtvbe6yIsGEIiIM9vnmjJlEpEvWrFcdrj1W+kfb+mJN2F2AEMTDwC9kMJWyDoq8GFTWk5eCO9iM291WICrAD3H XRZRsXhE DlyAVoidW/kofN50P55UR8h8DKFV8AITh0eNiHupnD6ZD3RQMXPAzyVYwDAkwQh17XiL3bi/XQ2aleVbNsRBYv7Y8D/bXAvme/Y6ntivOBlm+bPpKTQxJSbVpppkbQhFqeHIdOJu6ALXTYJkv6KCoeYo7TBvr0uzlCj/7IYD+6Zxj+PLdo03w9vUtQQ1M6c5+tWO+3PfHH9eHt0g+isUVOY2dPkjUBXQUp6MyWR34d5c9EHSFDMog1Kr5N0kAs5NRZDgGQWD6I0pO3v6Q7wxVEZTVHp6vXak9UfTacKz7DMwk4fcsGZWdmc1wuKBmGktpaWrOa/+7AvyFqLOdoAhGXOJ5VPWiqEqChEaL8rdU7ecagu2tLb/kmPzTJw5TX7gfc7wB/V6/ZbG76mS7TXwJxIT/gR6wgdq7I8BokGlvJTMKFlUSHVwBwFRfojg97H2cfBMZW+Z5EM/pG/CSEch/JUcNHZYuGzgk5uFhdQh0mwhwbjk2P7/4l9/ivbr0lGPOttvvNPl4eTqrwyCE+INfq7jc//y2salydFUiQ4yARvL/HupQW6ZP/0rxXbiq44J4khj6Ns18pTUXbOBRv6KnwMXmTaIImzpY4d5hQwSds5ZwwOrJDO1OhiIGGIOLGgF9HIXF6PPymrQGrc/cKEVpUMt8M3rxlTShmM+BW8541YTvfp/zfMy+u4b15on71cPnOTEJ7OFcRPni+nc= 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: 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) {