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 3D294C433EF for ; Fri, 1 Apr 2022 22:33:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94CEE8D0001; Fri, 1 Apr 2022 18:33:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FCC06B0072; Fri, 1 Apr 2022 18:33:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7758B8D0001; Fri, 1 Apr 2022 18:33:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0051.hostedemail.com [216.40.44.51]) by kanga.kvack.org (Postfix) with ESMTP id 68E896B0071 for ; Fri, 1 Apr 2022 18:33:14 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2A531825BA34 for ; Fri, 1 Apr 2022 22:33:04 +0000 (UTC) X-FDA: 79309761888.28.38D4C95 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf08.hostedemail.com (Postfix) with ESMTP id 333CE16001E for ; Fri, 1 Apr 2022 22:33:03 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0D4D0210EC; Fri, 1 Apr 2022 22:33:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1648852382; h=from:from:reply-to: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=IRwEXKyk8taU0Me5AEEyQ3cB4A5H97TBy7ejlW/HIGQ=; b=m4cUhr/sxBPUmUnvJET1mT2MQj56Munt/HKlCHinbCcWNZlilhx+3a2Ski2xUKFFQvj0Oa 7R2pk6LIwwILCU0gX13Hm8VYHK16djjHFJv0Cdn5WC4KODXPzhRvxI6gPwWwKW2RuFPbNZ cC54FbbhGr7Bf43d6R6GkAG1ZwjwlwA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1648852382; h=from:from:reply-to: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=IRwEXKyk8taU0Me5AEEyQ3cB4A5H97TBy7ejlW/HIGQ=; b=0B9HiZFJGZWUp+3U0avuQECt3wLMS2xSc8txXQS+xGNsJitRu8QZ1+FgEultE+t+jKae9z XuKlMatjV05i3GBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D08E6132C1; Fri, 1 Apr 2022 22:33:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7PjrMZ19R2KNNAAAMHmgww (envelope-from ); Fri, 01 Apr 2022 22:33:01 +0000 Message-ID: Date: Sat, 2 Apr 2022 00:33:00 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH v2 2/2] mm: wrap __find_buddy_pfn() with a necessary buddy page validation. Content-Language: en-US To: Zi Yan , Linus Torvalds Cc: Linux-MM , Steven Rostedt , David Hildenbrand , Mel Gorman , Mike Rapoport , Oscar Salvador , Andrew Morton , Linux Kernel Mailing List References: <20220401181109.1477354-1-zi.yan@sent.com> <20220401181109.1477354-2-zi.yan@sent.com> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: phtm3abgjq4gzy1jrbhhb1fzimcw9duo Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b="m4cUhr/s"; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=0B9HiZFJ; spf=pass (imf08.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 333CE16001E X-HE-Tag: 1648852383-807107 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 4/1/22 21:25, Zi Yan wrote: > On 1 Apr 2022, at 15:01, Linus Torvalds wrote: > >> On Fri, Apr 1, 2022 at 11:56 AM Zi Yan wrote: >>> >>> How about the patch below? If it looks good, I will send v3. >> >> I can't see anything worrisome, but by now I've looked at several >> versions and who knows what I'm missing. >> >> Making it inline and allowing a NULL 'buddy_pfn' pointer for the cases >> that don't care might be an option, but I don't think it matters >> hugely. > > What do you mean by inlining it? Moving the function and __find_buddy_pfn() > to mm/internal.h and mark both inline? I would prefer that for the sake of __free_one_page(). > Something like below to allow a NULL 'buddy_pfn'? buddy_pfn is needed > to store the result of __find_buddy_pfn(). The code does not look > as nice as before. > > struct page *find_buddy_page_pfn(struct page *page, unsigned long pfn, > unsigned int order, unsigned long *buddy_pfn) > { > struct page *buddy; > > if (buddy_pfn) { > *buddy_pfn = __find_buddy_pfn(pfn, order); > buddy = page + (*buddy_pfn - pfn); > } else > buddy = page + (__find_buddy_pfn(pfn, order) - pfn); > > if (page_is_buddy(page, buddy, order)) > return buddy; > return NULL; > } > > or > > struct page *find_buddy_page_pfn(struct page *page, unsigned long pfn, > unsigned int order, unsigned long *buddy_pfn) > { > struct page *buddy; > unsigned long local_buddy_pfn = __find_buddy_pfn(pfn, order); > > buddy = page + (local_buddy_pfn - pfn); > if (buddy_pfn) > *buddy_pfn = local_buddy_pfn; > > if (page_is_buddy(page, buddy, order)) > return buddy; > return NULL; > } The latter looks better. I would also use a name e.g. '__buddy_pfn' instead of 'local_'. Thanks. > > -- > Best Regards, > Yan, Zi