From patchwork Wed Jun 19 00:05:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13703198 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 EE804C27C4F for ; Wed, 19 Jun 2024 00:05:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E12E56B02C1; Tue, 18 Jun 2024 20:05:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D40B46B02BE; Tue, 18 Jun 2024 20:05:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0C056B02BD; Tue, 18 Jun 2024 20:05:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 747DF6B02B2 for ; Tue, 18 Jun 2024 20:05:31 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2064880AEF for ; Wed, 19 Jun 2024 00:05:31 +0000 (UTC) X-FDA: 82245694062.25.F74FE2D Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf21.hostedemail.com (Postfix) with ESMTP id E87BA1C0016 for ; Wed, 19 Jun 2024 00:05:28 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=licRGVV3; spf=pass (imf21.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718755523; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/OyteV4yM0qUOEafhhbvbTmI9bXZz54sg4qnQFhyy5A=; b=oX0bx11+y3R5EZ0aSOC7vV7GLjpBhfmgaYC3/yBkK5NUUYpZu1mh1riLQoqtkmrh2yxzrX hAmiCMzsp0o7LI30/FySPFju34RPf6CA1YmSfiM51zDVglLL/Br5Ca+zxkf18ZWRfr84C7 8t+djzhcu+/wNEjsIIlQU/iZsfZuowk= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=licRGVV3; spf=pass (imf21.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718755523; a=rsa-sha256; cv=none; b=sufk9vymVWFCmYjoRs/eiT3Vvb4OC4zfneC+PIk1AKOFpinfeZxq1qdnkA8d2pqHlO2qIz JdQ+kgVOvuM6nDw97tHiuhB+hh98lpOir5jisrkJk09xfRRAhHowDwHhl7j2Lsa9XMZLq9 IrB/MbA3diHCscsv5psgSfMQ1sPqd7k= Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45ILaNQ0001140; Wed, 19 Jun 2024 00:05:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= /OyteV4yM0qUOEafhhbvbTmI9bXZz54sg4qnQFhyy5A=; b=licRGVV3sGtCHq36 0d7qxPKp8nHzVyyyjoDtjlEIvyc2Yl9kIh+zg/1vUDXoiMeuH4qrR8zEBbzYvhCQ NUka56yx1u+Ai8QeAN5kLA66MICuH0QcNTBlA5cchSBCmxBCfR9SAatx+pkRTzTm U7JSMQHJjmxKZZ5qhWtr2sjgInmJwV+pwQWrv6eqnmFQWGNJI7kTZqe4CDsTYn+p rO7Fsy2I/oduWoMg66mamclM2wjvvYcWlIzaHJlxeGOKpUs/sDqA8E+tKKKQBQEw sznWTshLaFRzYo2tyLd5eaELSFmOvfjHrcBKRTRdLqyrO51KbVbmiZSfjF94kRxC y12OOQ== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yuja287fu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 00:05:18 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA03.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 45J05GcX029964 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Jun 2024 00:05:16 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Tue, 18 Jun 2024 17:05:16 -0700 From: Elliot Berman Date: Tue, 18 Jun 2024 17:05:07 -0700 Subject: [PATCH RFC 1/5] mm/gup: Move GUP_PIN_COUNTING_BIAS to page_ref.h MIME-Version: 1.0 Message-ID: <20240618-exclusive-gup-v1-1-30472a19c5d1@quicinc.com> References: <20240618-exclusive-gup-v1-0-30472a19c5d1@quicinc.com> In-Reply-To: <20240618-exclusive-gup-v1-0-30472a19c5d1@quicinc.com> To: Andrew Morton , Shuah Khan , David Hildenbrand , Matthew Wilcox , CC: , , , , , , Elliot Berman , Fuad Tabba X-Mailer: b4 0.13.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: eoEoI_FFBsbRB2SSN34e9igotn1wcWa9 X-Proofpoint-ORIG-GUID: eoEoI_FFBsbRB2SSN34e9igotn1wcWa9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-18_06,2024-06-17_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=684 suspectscore=0 clxscore=1015 impostorscore=0 malwarescore=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 spamscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406180176 X-Stat-Signature: oo1s5c1kr7edk83nz7axtz4gis3ctd5r X-Rspam-User: X-Rspamd-Queue-Id: E87BA1C0016 X-Rspamd-Server: rspam02 X-HE-Tag: 1718755528-246285 X-HE-Meta: U2FsdGVkX1/ThNVdAoMpn5j+JJ1gg0GHw+hHd3S8NFkAJWnzBcuRew+v5nFKLVixj9WUrkF3KighBeCLJUueYfKe2nFzu3kL4C4BpkoMNeKomIUMSt29tL3r0xJ2+nOKEUEqianMQtv4xpUGJazbsO8zK8yHpEJxbJP8vujmr9mBrBmT4sLJNw866219P2FZh+oeAV//YRKxSSuXGQ/GeYjJGznCSzHGj3LQG4F8iScBMNfQC/bH1HuUB5j10mdEI6qRHOTAld8MVQIG9PGPKXSCsiVodth71COr1KC1iCxKqZFQcQ3anWU9JY5Ph+SgvCusFMARq6LNNcqSN0yZROpBf+oKphc6XBPcD0NV33QlAp4lToNQjXHW1WbQKVk0DIokgm9lSdOZzYAvAvKoz6t3CyOYSqglBy4kIuTot8b5kG+7jQJG2k6NayDMIqxidTvHm437BwjATTojGxrCZfDmItkal0TgXGyBG8xAeNrwBOoaa9U5ujqQHEsxg5S8PPTGQihOIdmGOy72tv2KzokGNRQZF24mERuGDsoOUJP/H1rgpOR7v9w7WjrMst50fSHxrRo8JsqTrK/E9z8gMZJQsniL37VouZjkGP9rzvoGlXkVmTA2HOXTsZIDjLlW6/0BmovWpOKhAlM74r3lsiDOGsp6bcNBXzHUCr16huIynTxPHE44H2ggyicGa+wAh/JFjTLfKe5NhqkOLgGzrbfouoEJ7dq1BBMsT8ng1OqF/MNyB1Tp50c3zv4DLbosRWqFX6nfrMCJ5LQwbWtutqYdXLigaV2/zGWnUJzJZDf5YW/gBLeHBO0X4ABG47pCRnYrj+rpLh4rTFeVp0DgTrZNUchw7X9WiL0IfvWGikfoHUVo9Pbt1CLZ8WPtnmzD72ZwcwuC6tmOhC2VQONM6pJ/X1jskaJLJgNEwSfFuwPdmYm2mQppW5OxEtJ1G/7nYWMuH0PfDAsSRoyUAfZ YwE+ZGgD JPDyQdDLLoDgyCsO9Nidy0sT61DKPLKj2OjtwLusK2/Q5/x08ml0QboEsSNznqfsyp3KaYIaM3wRWDGJoxg+B4fHi9hGcs4gm2Mq80iJxXaxb5VG8hP0pOQbRiCo6UNts+gVkrQdJvzNsTx06RBjjtjta9KFxQJQXDvVFYvngGEBqZwz0eKH/Y9ZIMhE7MdOPah/T2JlM6hWvRVz2a9HVRC88jq6is3MfxpeW/AKSNyRkoSd5es0BGdxwg1AnTrhWCGs325yKOzVtJ5lRUjV6TDhe5a54ty4PziY0FiqrhpGprnrYE1s+CAg1LEJiegkX+XteDtbRviR1vR7Eq/7SmOJQVlw1VieqHW2WkT2JX5pAy1jNdxc55Avenw== 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: List-Subscribe: List-Unsubscribe: From: Fuad Tabba No functional change intended. Signed-off-by: Fuad Tabba Signed-off-by: Elliot Berman --- include/linux/mm.h | 32 -------------------------------- include/linux/page_ref.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 9849dfda44d43..fd0d10b08e7ac 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1580,38 +1580,6 @@ static inline void put_page(struct page *page) folio_put(folio); } -/* - * GUP_PIN_COUNTING_BIAS, and the associated functions that use it, overload - * the page's refcount so that two separate items are tracked: the original page - * reference count, and also a new count of how many pin_user_pages() calls were - * made against the page. ("gup-pinned" is another term for the latter). - * - * With this scheme, pin_user_pages() becomes special: such pages are marked as - * distinct from normal pages. As such, the unpin_user_page() call (and its - * variants) must be used in order to release gup-pinned pages. - * - * Choice of value: - * - * By making GUP_PIN_COUNTING_BIAS a power of two, debugging of page reference - * counts with respect to pin_user_pages() and unpin_user_page() becomes - * simpler, due to the fact that adding an even power of two to the page - * refcount has the effect of using only the upper N bits, for the code that - * counts up using the bias value. This means that the lower bits are left for - * the exclusive use of the original code that increments and decrements by one - * (or at least, by much smaller values than the bias value). - * - * Of course, once the lower bits overflow into the upper bits (and this is - * OK, because subtraction recovers the original values), then visual inspection - * no longer suffices to directly view the separate counts. However, for normal - * applications that don't have huge page reference counts, this won't be an - * issue. - * - * Locking: the lockless algorithm described in folio_try_get_rcu() - * provides safe operation for get_user_pages(), page_mkclean() and - * other calls that race to set up page table entries. - */ -#define GUP_PIN_COUNTING_BIAS (1U << 10) - void unpin_user_page(struct page *page); void unpin_user_pages_dirty_lock(struct page **pages, unsigned long npages, bool make_dirty); diff --git a/include/linux/page_ref.h b/include/linux/page_ref.h index 1acf5bac7f503..e6aeaafb143ca 100644 --- a/include/linux/page_ref.h +++ b/include/linux/page_ref.h @@ -62,6 +62,38 @@ static inline void __page_ref_unfreeze(struct page *page, int v) #endif +/* + * GUP_PIN_COUNTING_BIAS, and the associated functions that use it, overload + * the page's refcount so that two separate items are tracked: the original page + * reference count, and also a new count of how many pin_user_pages() calls were + * made against the page. ("gup-pinned" is another term for the latter). + * + * With this scheme, pin_user_pages() becomes special: such pages are marked as + * distinct from normal pages. As such, the unpin_user_page() call (and its + * variants) must be used in order to release gup-pinned pages. + * + * Choice of value: + * + * By making GUP_PIN_COUNTING_BIAS a power of two, debugging of page reference + * counts with respect to pin_user_pages() and unpin_user_page() becomes + * simpler, due to the fact that adding an even power of two to the page + * refcount has the effect of using only the upper N bits, for the code that + * counts up using the bias value. This means that the lower bits are left for + * the exclusive use of the original code that increments and decrements by one + * (or at least, by much smaller values than the bias value). + * + * Of course, once the lower bits overflow into the upper bits (and this is + * OK, because subtraction recovers the original values), then visual inspection + * no longer suffices to directly view the separate counts. However, for normal + * applications that don't have huge page reference counts, this won't be an + * issue. + * + * Locking: the lockless algorithm described in folio_try_get_rcu() + * provides safe operation for get_user_pages(), page_mkclean() and + * other calls that race to set up page table entries. + */ +#define GUP_PIN_COUNTING_BIAS (1U << 10) + static inline int page_ref_count(const struct page *page) { return atomic_read(&page->_refcount);