From patchwork Wed Apr 4 19:17:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Glisse X-Patchwork-Id: 10323297 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 391516032A for ; Wed, 4 Apr 2018 19:32:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2ABEE28F65 for ; Wed, 4 Apr 2018 19:32:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FB7B28F6B; Wed, 4 Apr 2018 19:32:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 868C628F65 for ; Wed, 4 Apr 2018 19:32:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751710AbeDDTcM (ORCPT ); Wed, 4 Apr 2018 15:32:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35142 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751470AbeDDTTC (ORCPT ); Wed, 4 Apr 2018 15:19:02 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7CBEEEB6F6; Wed, 4 Apr 2018 19:19:01 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-125-89.rdu2.redhat.com [10.10.125.89]) by smtp.corp.redhat.com (Postfix) with ESMTP id B86B88443C; Wed, 4 Apr 2018 19:19:00 +0000 (UTC) From: jglisse@redhat.com To: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org Cc: linux-kernel@vger.kernel.org, =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Andrew Morton , Alexander Viro , Tejun Heo , Jan Kara , Josef Bacik , Mel Gorman Subject: [RFC PATCH 06/79] mm/page: add helpers to dereference struct page index field Date: Wed, 4 Apr 2018 15:17:53 -0400 Message-Id: <20180404191831.5378-4-jglisse@redhat.com> In-Reply-To: <20180404191831.5378-1-jglisse@redhat.com> References: <20180404191831.5378-1-jglisse@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 04 Apr 2018 19:19:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Wed, 04 Apr 2018 19:19:01 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jglisse@redhat.com' RCPT:'' Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jérôme Glisse Regroup all helpers that dereference struct page.index field into one place and require a the address_space (mapping) against which caller is looking the index (offset, pgoff, ...) Signed-off-by: Jérôme Glisse Cc: linux-mm@kvack.org CC: Andrew Morton Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Cc: Tejun Heo Cc: Jan Kara Cc: Josef Bacik Cc: Mel Gorman --- include/linux/mm-page.h | 136 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/mm.h | 5 ++ 2 files changed, 141 insertions(+) create mode 100644 include/linux/mm-page.h diff --git a/include/linux/mm-page.h b/include/linux/mm-page.h new file mode 100644 index 000000000000..2981db45eeef --- /dev/null +++ b/include/linux/mm-page.h @@ -0,0 +1,136 @@ +/* + * Copyright 2018 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * Authors: Jérôme Glisse + */ +/* + * This header file regroup everything that deal with struct page and has no + * outside dependency except basic types header files. + */ +/* Protected against rogue include ... do not include this file directly */ +#ifdef DOT_NOT_INCLUDE___INSIDE_MM +#ifndef MM_PAGE_H +#define MM_PAGE_H + +/* External struct dependencies: */ +struct address_space; + +/* External function dependencies: */ +extern pgoff_t __page_file_index(struct page *page); + + +/* + * _page_index() - return page index value (with special case for swap) + * @page: page struct pointer for which we want the index value + * @mapping: mapping against which we want the page index + * Returns: index value for the page in the given mapping + * + * The index value of a page is against a given mapping and page which belongs + * to swap cache need special handling. For swap cache page what we want is the + * swap offset which is store encoded with other fields in page->private. + */ +static inline unsigned long _page_index(struct page *page, + struct address_space *mapping) +{ + if (unlikely(PageSwapCache(page))) + return __page_file_index(page); + return page->index; +} + +/* + * _page_set_index() - set page index value against a give mapping + * @page: page struct pointer for which we want the index value + * @mapping: mapping against which we want the page index + * @index: index value to set + */ +static inline void _page_set_index(struct page *page, + struct address_space *mapping, + unsigned long index) +{ + page->index = index; +} + +/* + * _page_to_index() - page index value against a give mapping + * @page: page struct pointer for which we want the index value + * @mapping: mapping against which we want the page index + * Returns: index value for the page in the given mapping + * + * The index value of a page is against a given mapping. THP page need special + * handling has the index is set in the head page thus the final index value is + * the tail page index plus the number of page from current page to head page. + */ +static inline unsigned long _page_to_index(struct page *page, + struct address_space *mapping) +{ + unsigned long pgoff; + + if (likely(!PageTransTail(page))) + return page->index; + + /* + * We don't initialize ->index for tail pages: calculate based on + * head page + */ + pgoff = compound_head(page)->index; + pgoff += page - compound_head(page); + return pgoff; +} + +/* + * _page_to_pgoff() - page pgoff value against a give mapping + * @page: page struct pointer for which we want the index value + * @mapping: mapping against which we want the page index + * Returns: pgoff value for the page in the given mapping + * + * The pgoff value of a page is against a given mapping. Hugetlb pages need + * special handling as for they have page->index in size of the huge pages + * (PMD_SIZE or PUD_SIZE), not in PAGE_SIZE as other types of pages. + * + * FIXME convert hugetlb to multi-order entries. + */ +static inline unsigned long _page_to_pgoff(struct page *page, + struct address_space *mapping) +{ + if (unlikely(PageHeadHuge(page))) + return page->index << compound_order(page); + + return _page_to_index(page, mapping); +} + +/* + * _page_offset() - page offset (in bytes) against a give mapping + * @page: page struct pointer for which we want the index value + * @mapping: mapping against which we want the page index + * Returns: page offset (in bytes) for the page in the given mapping + */ +static inline unsigned long _page_offset(struct page *page, + struct address_space *mapping) +{ + return page->index << PAGE_SHIFT; +} + +/* + * _page_file_offset() - page offset (in bytes) against a give mapping + * @page: page struct pointer for which we want the index value + * @mapping: mapping against which we want the page index + * Returns: page offset (in bytes) for the page in the given mapping + */ +static inline unsigned long _page_file_offset(struct page *page, + struct address_space *mapping) +{ + return page->index << PAGE_SHIFT; +} + +#endif /* MM_PAGE_H */ +#endif /* DOT_NOT_INCLUDE___INSIDE_MM */ diff --git a/include/linux/mm.h b/include/linux/mm.h index ad06d42adb1a..874a10f011ee 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2673,5 +2673,10 @@ void __init setup_nr_node_ids(void); static inline void setup_nr_node_ids(void) {} #endif +/* Include here while header consolidation process is in progress */ +#define DOT_NOT_INCLUDE___INSIDE_MM +#include +#undef DOT_NOT_INCLUDE___INSIDE_MM + #endif /* __KERNEL__ */ #endif /* _LINUX_MM_H */