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 X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51A94C433E2 for ; Thu, 25 Mar 2021 12:41:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 276F661A1D for ; Thu, 25 Mar 2021 12:41:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231231AbhCYMlB (ORCPT ); Thu, 25 Mar 2021 08:41:01 -0400 Received: from outbound-smtp20.blacknight.com ([46.22.139.247]:52073 "EHLO outbound-smtp20.blacknight.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231219AbhCYMkf (ORCPT ); Thu, 25 Mar 2021 08:40:35 -0400 Received: from mail.blacknight.com (pemlinmail06.blacknight.ie [81.17.255.152]) by outbound-smtp20.blacknight.com (Postfix) with ESMTPS id DDAB41C35FC for ; Thu, 25 Mar 2021 12:40:33 +0000 (GMT) Received: (qmail 19824 invoked from network); 25 Mar 2021 12:40:33 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.22.4]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 25 Mar 2021 12:40:33 -0000 Date: Thu, 25 Mar 2021 12:40:32 +0000 From: Mel Gorman To: Matthew Wilcox Cc: Andrew Morton , Chuck Lever , Jesper Dangaard Brouer , Christoph Hellwig , Alexander Duyck , Vlastimil Babka , Ilias Apalodimas , LKML , Linux-Net , Linux-MM , Linux-NFS Subject: Re: [PATCH 4/9] mm/page_alloc: optimize code layout for __alloc_pages_bulk Message-ID: <20210325124032.GR3697@techsingularity.net> References: <20210325114228.27719-1-mgorman@techsingularity.net> <20210325114228.27719-5-mgorman@techsingularity.net> <20210325121217.GV1719932@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <20210325121217.GV1719932@casper.infradead.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 25, 2021 at 12:12:17PM +0000, Matthew Wilcox wrote: > On Thu, Mar 25, 2021 at 11:42:23AM +0000, Mel Gorman wrote: > > > > - if (WARN_ON_ONCE(nr_pages <= 0)) > > + if (unlikely(nr_pages <= 0)) > > return 0; > > If we made nr_pages unsigned, we wouldn't need this check at all (ok, > we'd still need to figure out what to do with 0). But then, if a user > inadvertently passes in -ENOMEM, we'll try to allocate 4 billion pages. This is exactly why nr_pages is signed. An error in accounting by the caller potentially puts the system under severe memory pressure. This *should* only be a problem when a new caller of the API is being implemented. The warning goes away in a later patch for reasons explained in the changelog. > So maybe we should check it. Gah, API design is hard. Yep. -- Mel Gorman SUSE Labs