From patchwork Fri Apr 14 00:11:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13210785 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 704B7C77B6F for ; Fri, 14 Apr 2023 00:12:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCFD46B0075; Thu, 13 Apr 2023 20:12:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D586E6B0078; Thu, 13 Apr 2023 20:12:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5D2E900002; Thu, 13 Apr 2023 20:12:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A5B2F6B0075 for ; Thu, 13 Apr 2023 20:12:03 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 76268C04C7 for ; Fri, 14 Apr 2023 00:12:03 +0000 (UTC) X-FDA: 80678068926.25.EBA9467 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf08.hostedemail.com (Postfix) with ESMTP id A4B34160006 for ; Fri, 14 Apr 2023 00:12:01 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=S5LluL5N; spf=pass (imf08.hostedemail.com: domain of 3UJo4ZAsKCI8tv3xA4xHC6zz77z4x.v75416DG-553Etv3.7Az@flex--ackerleytng.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3UJo4ZAsKCI8tv3xA4xHC6zz77z4x.v75416DG-553Etv3.7Az@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=1681431121; 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=LGz+M9nFtzHbGGbLaqDB42+XLCRk5tnoOBaeHE6w0dg=; b=0pWzozyYPVT7cu6rgiWgAt3QYzSxd4Ii02xI1n/BSkuhLX9B1HRwby2/a2OSUKBx/dWS0g fsiVx97cFfdAjwxFsdKzWu5Av0247ZQoNYKlTXvwTBIqTsmd8MRw0WAyMxY3cL4NfjnZ8l aak5cH6qjFrDV8z8Prf0LyM3FRXmw3s= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=S5LluL5N; spf=pass (imf08.hostedemail.com: domain of 3UJo4ZAsKCI8tv3xA4xHC6zz77z4x.v75416DG-553Etv3.7Az@flex--ackerleytng.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3UJo4ZAsKCI8tv3xA4xHC6zz77z4x.v75416DG-553Etv3.7Az@flex--ackerleytng.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681431121; a=rsa-sha256; cv=none; b=GV0MMnSBG1YqRbFITJ+X3kXFMe8eLkQvtKvPLRXXARCPXJzHD1/dmR67MNsy+xzA4JzEUK DppnHQA9leDaJ21AlxcuVzAeUEeIE3g3znFaykKEN0YnyJdDLARBhy0mDnMnJuEnBr3F9s cq4Yvz5pCJQKsXI0NphE1DjvWp5PsaM= Received: by mail-pg1-f201.google.com with SMTP id g129-20020a636b87000000b005072b17a298so7104305pgc.14 for ; Thu, 13 Apr 2023 17:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681431120; x=1684023120; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LGz+M9nFtzHbGGbLaqDB42+XLCRk5tnoOBaeHE6w0dg=; b=S5LluL5NFzRfMffvrC48pA8vM9jBztEWtYOdVu6RC2ufBdtUUSqD+XyBpvK1yq+IN2 IHnZhiT1W0yssxQ4r7Y9clMkV6zvB2ogiOPODlbRwrRyDr07/qDDpZBBDVLk/N65uZzy CN1ozoAyt0GCn/Q/UB/ZvGZUO3F2PMmedv6i9jH6jJ0uY0cAH01PJa7G0h1cPoPbYq3f IdXBPJH4a6Ro/C6Sct1ltwBhbcLCAMsdz4Y30Y2jgpBNq+x1h2YwjODMyjFmoi8MJRCf dDhFwUgzHhEfG/8I1Qg7KrBG7Crz9lPVWk5qe+WYi0MTtv3ZN9nLmsTMDMwmdbsD2L57 OQPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681431120; x=1684023120; 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=LGz+M9nFtzHbGGbLaqDB42+XLCRk5tnoOBaeHE6w0dg=; b=IRxkFMuc1JpHhwEaWtLm0flqxYswm8NhG8WqMS9JyNqcWT7vPWIN0ZgpihntdGNbKR rYcSoQl8Q0NmHEfucFFWuFUVlEeIFrlNziyOUKFF0tBQ+lzqN5QZ1eDkMffFbWIXv1Do i++OfwN00bOA+yDY+ysmqypBzajlFFtx8tSxzbkUF8Gb863iq88RIyhuQIJOJ81rWeOG pH7rR65Zv0RFDy+qptAxE0UF3FMp7SPxsC9IVTtvKlHUqzUi3lLlz9L3RGC3SZ6aWETh KZz8qy3JZWT5Kt1DQJgSuboha9G9dEvRzEeDa4/ZR9oCJvWxOkbnCJ/7tV2nQ67Idtqm /ebg== X-Gm-Message-State: AAQBX9cvmFnAyxDpx3D+7rTa5CzoAucf/Tcvn+RfIlB8DBl2I+T/e2h8 YS3BmXtJnsFp3KuFzAMCmjx3dhEMB8A1z3ruCQ== X-Google-Smtp-Source: AKy350YIYIzzkTKMTgAPyGCMhA2HHi565MHAj4RU3xofJGGDi/ggUb7Aj3J6+1abX8zL+AMGXGGHN+6shLHAP2f2mA== X-Received: from ackerleytng-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1f5f]) (user=ackerleytng job=sendgmr) by 2002:a17:902:bd90:b0:19a:f9d9:28d4 with SMTP id q16-20020a170902bd9000b0019af9d928d4mr282396pls.3.1681431120479; Thu, 13 Apr 2023 17:12:00 -0700 (PDT) Date: Fri, 14 Apr 2023 00:11:50 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog Message-ID: <476aa5a107994d293dcdfc5a620cc52f625768c2.1681430907.git.ackerleytng@google.com> Subject: [RFC PATCH 1/6] mm: shmem: Refactor out shmem_shared_policy() function 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: A4B34160006 X-Stat-Signature: ubjpsgwi8qnrg8dyw7z4jo5ub4idir1b X-Rspam-User: X-HE-Tag: 1681431121-908693 X-HE-Meta: U2FsdGVkX19fFVtaD7p+riuUp5LKuTuSAQVSu1OEX2it21JV+dCUok2O4WK22YX3v3JqishxcIHzD568RIP2XJKFJ8a7GbCGaPhcyyEH4NDPLt3YzXtt/ez4SiAtQzEle/jh7Y+/KYyJRkqOHuO4h2LIgG8VmqSsoX+pAvg9UqlBViq3YwWocFeWNWVYd9FkJFmCH3BwkPaK+KYsw38qmutXRLlODNxloT5nrGGNhzGrO2nSZDv1uHKrQDwLcnFfyPrKZPLMDO34kId5J7KJ0qPTL2TKN43EtdDpm7YeDf4+FZtCFjBU+c6bM/bBTyBh+GOOZM3g2QVxim9KI11dmiNwM/JGMvoHhfY8ASPQPsWQToJj3k1upJOAMNh2zMGZA76RxFoPtw6Cjo0g9I/MKzCtww0ieFWjwdEGMmCNlPL/nxRl79TMWa3gG1fFZsYTFBx/XJT7VDLRXVj5TFIHN5P/gTkSkzqrBlb9YB/ewsj2Nv/D4HxkcMgHEiR4vFcLur86K4Dyb7URLgN6/OinXEXv6nGhyJqpGEpD/aBt7Azzocc+sJWg41Ium83xN0l9mc4Y4w9MQHFit5c4I68QtZ3f5eEJFaNJUg35JZ2B/D4VgKyPSu12MKcDkd3IXMOG/Rdcu5+tk3IsNJA6NBXUFbadbBn7K2x1iVUyIfRdCxVyZYuARMCeyr6e3EgvtB6jyuK9qYB9sCyC56jhU1aU9XI4K/MkP9auqcInkcdtxkz+uETKLrNbO8ZeI8YkHBkKcoln3PnQtOZw5c+hMXQHkDN4EpSMmzb1KEz9QGKp41Nc+hQ1U7X4xR7djFHU5GOdXVKaGDtv+9bYG71yq92UbA+fP/Cvp5Ok+1SfcS0jAuThwjLlwXYo9FvtDeg9D3XoYxj0rSvOVkZtPcu18wXnWGCxMRc+YloHDtnYoCdkk/o/XgBAuyc9VUphcTg/gJteoRbaRVgyZZ24auE2VOJ ah/FJY/N xEyMnZstQ+d4lJ8//rGp4huo492Lu8NFDX+18Rp56jrN30CG8eGCzvwDjyJAxckisaHKbD9q5NPkKYZMJ/ixDe4bg+afeiT++TNyy7Mj/INIPZhRFkoeDN0UrPh/ovt8vZ/gbSSO7fIDM8ny0YiyX9avwe4gs9m2mhedSR+hLt6qI4doHIQpCOFvA6r3//CW1Q98mX+BI3wl1/LmQxpsY4gfhAtfb9KydkX0CCeujwKjyPYF5YYE0TfgFZNOIS5KaF7ld0fgUXr5jBEmQDv0USpreQmQfbNLt8AwOnEbnMQK9zII7lqIHwV0DjeZdYFQLuavJZGA+B/twP7saz/rqfIzftlKDMmz2HF4aL3Rpo4AeJIYn7Emt1lORkOPlyF2uCa5bPhz4g47qKYx4Au/tZPmeiW2BHvGw8kKPFYtnm6sUKEQzqbDK0isoX05g5mjIrMRROPDipMLXXS8g8iUVAqHXiiyGmMiCZq5aVEf2IW0IZUd4NNG4sJEqM600o1Pk424bhJS7y0BQe5mzHOPfjssUpytFQkDDroxHJK9glsVrxRWWA+i2wH2S2ouzvogxfLqJ7R9Gy859O4UMeNNB/rppICobqBXDauLsKDG98Sjww5Sg8NoDbHHRksq4AutC5jpFUKfm6DhVgvzPv5YzQwD4zmRlIEcc7D5sNcMaJBbJ1dgGSGuIsGG0UFJoDfYU34Fo508TQ5ppfMU= 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 shmem_shared_policy() to allow reading of a file's shared mempolicy Signed-off-by: Ackerley Tng --- include/linux/shmem_fs.h | 7 +++++++ mm/shmem.c | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index d9e57485a686..bc1eeb4b4bd9 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -134,6 +134,13 @@ static inline bool shmem_file(struct file *file) return shmem_mapping(file->f_mapping); } +static inline struct shared_policy *shmem_shared_policy(struct file *file) +{ + struct inode *inode = file_inode(file); + + return &SHMEM_I(inode)->policy; +} + /* * If fallocate(FALLOC_FL_KEEP_SIZE) has been used, there may be pages * beyond i_size's notion of EOF, which fallocate has committed to reserving: diff --git a/mm/shmem.c b/mm/shmem.c index b053cd1f12da..4f801f398454 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2248,20 +2248,22 @@ unsigned long shmem_get_unmapped_area(struct file *file, } #ifdef CONFIG_NUMA + static int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *mpol) { - struct inode *inode = file_inode(vma->vm_file); - return mpol_set_shared_policy(&SHMEM_I(inode)->policy, vma, mpol); + struct shared_policy *info; + + info = shmem_shared_policy(vma->vm_file); + return mpol_set_shared_policy(info, vma, mpol); } static struct mempolicy *shmem_get_policy(struct vm_area_struct *vma, unsigned long addr) { - struct inode *inode = file_inode(vma->vm_file); pgoff_t index; index = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; - return mpol_shared_policy_lookup(&SHMEM_I(inode)->policy, index); + return mpol_shared_policy_lookup(shmem_shared_policy(vma->vm_file), index); } #endif