From mboxrd@z Thu Jan 1 00:00:00 1970 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 DB475C4708D for ; Thu, 8 Dec 2022 02:19:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 226B18E0007; Wed, 7 Dec 2022 21:19:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1AF0B8E0001; Wed, 7 Dec 2022 21:19:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04F038E0007; Wed, 7 Dec 2022 21:19:45 -0500 (EST) 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 E549B8E0001 for ; Wed, 7 Dec 2022 21:19:45 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BD9A6C0110 for ; Thu, 8 Dec 2022 02:19:45 +0000 (UTC) X-FDA: 80217533130.05.A0E277B Received: from out-162.mta0.migadu.com (out-162.mta0.migadu.com [91.218.175.162]) by imf12.hostedemail.com (Postfix) with ESMTP id ABE9D40009 for ; Thu, 8 Dec 2022 02:19:43 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=McDnxzI+; spf=pass (imf12.hostedemail.com: domain of muchun.song@linux.dev designates 91.218.175.162 as permitted sender) smtp.mailfrom=muchun.song@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670465984; 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=QSszmN9yN6kL/If3FUicQlBPIM/TWwMp6cm84keStsE=; b=ARltTbkGvUGzKKgwiutrF6qU2xprsRmNupRJO1VnkOd3C0CrvaNHIYrlWbKsWMwygjtB8Z QR4bG0q1jw+G3cNyh7wJOy5GubOscrdG8JVe9ixop0TBp68cNKFyFj2zo6SXdHR7STS76s RSk1ZkQLPyf2G8daOyL3EIC7ELmZPSs= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=McDnxzI+; spf=pass (imf12.hostedemail.com: domain of muchun.song@linux.dev designates 91.218.175.162 as permitted sender) smtp.mailfrom=muchun.song@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670465984; a=rsa-sha256; cv=none; b=ou8FEQj1H/JRFdVUJkNx+Piehc3i83/2SrAy0Ce/nr15p8lqSBijzMxZn33qYCmSFg15y0 MpsQeNmOEUvOd9F2YeA3DOlsByBEyijhSQEYAKFCmztyDAM2Eb52kL5yWv3p4LBLOC+HPZ lh0rUPazP3Ym7EnpjBoB4EGEnzTZQPU= Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1670465981; h=from:from: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; bh=QSszmN9yN6kL/If3FUicQlBPIM/TWwMp6cm84keStsE=; b=McDnxzI+sO7YBXmTXAqYqIu4KjUgkN3bguA1allYKj5IF9oelaD0nkCMpRHqxNrdaWhMJF Wuj0MSQ6cn5S6WPDxnqwDc++AyB2x3B4D8tnIMj9V+jn80uIeb3eCCJYk8mXEoSywwgE0d wLyVK+g/FC0KIfLJRZCBdQCsqjttpMM= Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.200.110.1.12\)) Subject: Re: [PATCH mm-unstable v5 01/10] mm: add folio dtor and order setter functions X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: Date: Thu, 8 Dec 2022 10:19:24 +0800 Cc: Sidhartha Kumar , linux-kernel@vger.kernel.org, Linux Memory Management List , Andrew Morton , Muchun Song , Matthew Wilcox , Mina Almasry , Miaohe Lin , hughd@google.com, tsahu@linux.ibm.com, jhubbard@nvidia.com, David Hildenbrand Content-Transfer-Encoding: quoted-printable Message-Id: <3F95112C-C1B3-4774-9E21-998CADEC38D4@linux.dev> References: <20221129225039.82257-1-sidhartha.kumar@oracle.com> <20221129225039.82257-2-sidhartha.kumar@oracle.com> <4161AF1A-9508-4DF8-B756-FEB476EB32B5@linux.dev> To: Mike Kravetz X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: ABE9D40009 X-Stat-Signature: aoxpdnimhc4r1hxe7mcc665oqjnssisu X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1670465983-344429 X-HE-Meta: U2FsdGVkX1/IpRSWUmG5B+uDwWn5K3cQ+uHosHPf909++WIs2a+srlfLzC1sAEBOAvRq9Sb5fLvTSiWn0lgFE8fq+gUObwzJv8zqiYkygj8MptpYDqgZ2yORhFOj30GwlbVmWVo6yWUZeeJyLsRgOSVXivRRPzT0DROX0aCUvJiO4RF+rytGw6latMRvrpHVfKdfUhZgBJQhGeqtwR+p6Nt1EAlnYXkMlkRQWzJzq2CV+Gex4glE/UM/mLpo7wO7OUqD4Hnpgzzv3lhsVy2zOcJJxbNI+AVVxkhvcQiVwz4xeA6bpjq5MOZ5Vwr3DeDQoIW92Yc1NBL1z+2/R6tjuMBdpYHc+A45MQ9smnDsD2RF+DQNLrQ9ySZNOvcsnCtD75bm4VeTCYHBf4IKRTWFtp7cawzGRtddLYJUebdqMa9DYAvdE4x/81DbffPdf0c9kLIQc+1TAnY5NuZsItROyUsrsoLWoQ7RNVseY99HqbmBZthZVxQLe3WLeGAgkjBaeya6dlu5YzK0oXjbDlEGfsNuaggzLhV+rjkJz62pqLEizoqrf5/hrbEhdQRfqJul/MRHhzPLdIQh7vTqcElXvuEW8SwH7zHAQe6BhmX0+sBqWRVoSMM9A2ppKcg7IbeKPUhcAu400rqkItRqplXLJiP7XkZ144wtoZUcDW7t3j8Teqlb6O6h408KTj5ljyjD1YwxuqtkB6BmtH02x5YFigQqQTmyvC/lmeFDZPFZR3BO4W4oaS/DnTa/B7NYV+1zr8afdeIaeBLyovQwB/qPRw93FGiTOAE6nFGFFHxxCZNCwdR9HPTum5zbq1/NhV2UlpR0SIwzYNO9BgWBsNMRS+QAnS30Q8MQ 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: > On Dec 8, 2022, at 03:25, Mike Kravetz = wrote: >=20 > On 12/07/22 11:05, Sidhartha Kumar wrote: >> On 12/7/22 10:49 AM, Sidhartha Kumar wrote: >>> On 12/7/22 10:12 AM, Mike Kravetz wrote: >>>> On 12/07/22 12:11, Muchun Song wrote: >>>>>> On Dec 7, 2022, at 11:42, Mike Kravetz = wrote: >>>>>> On 12/07/22 11:34, Muchun Song wrote: >>>>>=20 >>>>> Agree. It has confused me a lot. I suggest changing the code to = the >>>>> followings. The folio_test_large() check is still to avoid = unexpected >>>>> users for OOB. >>>>>=20 >>>>> static inline void folio_set_compound_order(struct folio *folio, >>>>> unsigned int order) >>>>> { >>>>> VM_BUG_ON_FOLIO(!folio_test_large(folio), folio); >>>>> // or >>>>> // if (!folio_test_large(folio)) >>>>> // return; >>>>>=20 >>>>> folio->_folio_order =3D order; >>>>> #ifdef CONFIG_64BIT >>>>> folio->_folio_nr_pages =3D order ? 1U << order : 0; >>>>> #endif >>>>> } >>>>=20 >>>> I think the VM_BUG_ON_FOLIO is appropriate as it would at least = flag >>>> data corruption. >>>>=20 >>> As Mike pointed out, my intention with supporting the 0 case was to >>> cleanup the __destroy_compound_gigantic_page code by moving the = ifdef >>> CONFIG_64BIT lines to folio_set_compound_order(). I'll add the >>> VM_BUG_ON_FOLIO line as well as a comment to make it clear it is not >>> normally supported. >>>=20 >>>> Thinking about this some more, it seems that hugetlb is the only = caller >>>> that abuses folio_set_compound_order (and previously = set_compound_order) >>>> by passing in a zero order. Since it is unlikely that anyone knows = of >>>> this abuse, it might be good to add a comment to the routine to = note >>>> why it handles the zero case. This might help prevent changes = which >>>> would potentially break hugetlb. >>>=20 >>> +/* >>> + * _folio_nr_pages and _folio_order are invalid for >>> + * order-zero pages. An exception is hugetlb, which passes >>> + * in a zero order in __destroy_compound_gigantic_page(). >>> + */ >>> static inline void folio_set_compound_order(struct folio *folio, >>> unsigned int order) >>> { >>> + VM_BUG_ON_FOLIO(!folio_test_large(folio), folio); >>> + >>> folio->_folio_order =3D order; >>> #ifdef CONFIG_64BIT >>> folio->_folio_nr_pages =3D order ? 1U << order : 0; >>>=20 >>> Does this comment work? >>>=20 >>>=20 >>=20 >> I will change the comment from referencing >> __destory_compound_gigantic_page() >> to __destroy_compound_gigantic_folio, although >> __prep_compound_gigantic_folio() is another user of >> folio_set_compound_order(folio, 0). Should the sentence just be "An >> exception is hugetlb, which passes in a zero order"? >=20 > How about a comment like this? >=20 > /* > * folio_set_compound_order is generally passed a non-zero order to > * set up/create a large folio. However, hugetlb code abuses this by > * passing in zero when 'dissolving' a large folio. > */ How about adding a new helper like "folio_dissolve_compound(struct folio = *folio)"? then it may be unnecessary to add a comment. Thanks. >=20 > My only concern is that someone may modify the routine such that it no > longer works when passed zero order. It is not likely as anyone = should > notice the special case for zero, and look for callers. > --=20 > Mike Kravetz