Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2648741pxa; Mon, 24 Aug 2020 22:14:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBn/Zk73yDNCwl9ohTymYIxTn3jGTc+4/5RCnB1eLTBObNx6MdC0jyYgVAO6Hl9OZZ0qmA X-Received: by 2002:a17:906:4755:: with SMTP id j21mr9378232ejs.422.1598332441243; Mon, 24 Aug 2020 22:14:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598332441; cv=none; d=google.com; s=arc-20160816; b=hqtvnjBF6QuFoMAGcoLeXOsT3/5D9VNBkCIpOTGX9rX74IfN6JPeYTQtvnU70/Ism+ qPuLz66nkMVELZFfUoz/B4+yKK/o+tu4RiNfKTYJeO43q9T9M09c8zgUV2Xq9BTGcW61 /hFNdx1qsDFNZ8XNAdLkm8pC3O32T3LsddI2vz6vPKVDOJFhJneBxp8FpLHRB5gLs/Mu SZys8XwpkPBj6VPt2uvj3c4CpVM8fHkO0aZ2n4g3OBXHs2qaoU3BafWRHM23LE3MxdvG i6wZev9/2oUQo4DGD7/nygEVLFLwM8Ta2jhVMNqNlyvEcLbIvRsiGUAhTRabyMqXQrGn YRiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=aGwr3QvdAZ+QFoUoRj/Hoq+uFqV0grwUdrZFFV5XDJU=; b=PlyDExYtzpuduLBqLeoPj+xC61NsMfOHiP/UTtve8tfvIsBsq4ocSYA9FFPiqjdQUJ TpmQFTCADldlAltJZc+enRV9uutLW25fEH/AhODRXmih7aBbGNy7+xXUO3rVBCRL0Lqq sPgELDB8RgD6SNY0/8HqkNACMJ7jpB37Koj50mIv+m8X1Ll83fl6CBGkwuCgL7hRm2Eh zrwdSiJjntl9dWPcnpC53cDbLpZTh+yauE5lEDweiVnudJXNzsgJKzaXHxkyOGfbs/8l sJNsg0Egs+bhDEnCWt8fPirvfXphlPUgxfE+Ayha9qYR9z3UCY6LEhCj7pSNKygmXEaX +lRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T43Wjah6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i11si10060881edb.127.2020.08.24.22.13.37; Mon, 24 Aug 2020 22:14:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=T43Wjah6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726619AbgHYFKv (ORCPT + 99 others); Tue, 25 Aug 2020 01:10:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:55148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725781AbgHYFKv (ORCPT ); Tue, 25 Aug 2020 01:10:51 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 27D782071E; Tue, 25 Aug 2020 05:10:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598332250; bh=Tm5TGS9QxUQnZMSBd7cObay8VgPGZsJUas2eWOf9csE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=T43Wjah61jO7E4dy/ROpCXV6YaMsYbfXW65GEfmoSfuVTQHHiONBQPnQ9AHvCiKKZ FnENnMAAPPpMAXEuoT5HpmlSTg1/Sfix7DgfKuLLIASWuAlEajxtod+WhD9StoKoVB kbV5AUYwDsPcWT8q18WH9VdGEL5wj/mrD3m6lKcg= Date: Mon, 24 Aug 2020 22:10:49 -0700 From: Andrew Morton To: js1304@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Michal Hocko , Vlastimil Babka , "Aneesh Kumar K . V" , kernel-team@lge.com, Joonsoo Kim Subject: Re: [PATCH for v5.9] mm/page_alloc: handle a missing case for memalloc_nocma_{save/restore} APIs Message-Id: <20200824221049.edb3c540bbfc859a6806600d@linux-foundation.org> In-Reply-To: <1598331582-19923-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1598331582-19923-1-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 25 Aug 2020 13:59:42 +0900 js1304@gmail.com wrote: > From: Joonsoo Kim > > memalloc_nocma_{save/restore} APIs can be used to skip page allocation > on CMA area, but, there is a missing case and the page on CMA area could > be allocated even if APIs are used. This patch handles this case to fix > the potential issue. > > Missing case is an allocation from the pcplist. MIGRATE_MOVABLE pcplist > could have the pages on CMA area so we need to skip it if ALLOC_CMA isn't > specified. > > This patch implements this behaviour by checking allocated page from > the pcplist rather than skipping an allocation from the pcplist entirely. > Skipping the pcplist entirely would result in a mismatch between watermark > check and actual page allocation. And, it requires to break current code > layering that order-0 page is always handled by the pcplist. I'd prefer > to avoid it so this patch uses different way to skip CMA page allocation > from the pcplist. > > ... > > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -3341,6 +3341,22 @@ static struct page *rmqueue_pcplist(struct zone *preferred_zone, > pcp = &this_cpu_ptr(zone->pageset)->pcp; > list = &pcp->lists[migratetype]; > page = __rmqueue_pcplist(zone, migratetype, alloc_flags, pcp, list); > +#ifdef CONFIG_CMA > + if (page) { > + int mt = get_pcppage_migratetype(page); > + > + /* > + * pcp could have the pages on CMA area and we need to skip it > + * when !ALLOC_CMA. Free all pcplist and retry allocation. > + */ > + if (is_migrate_cma(mt) && !(alloc_flags & ALLOC_CMA)) { > + list_add(&page->lru, &pcp->lists[migratetype]); > + pcp->count++; > + free_pcppages_bulk(zone, pcp->count, pcp); > + page = __rmqueue_pcplist(zone, migratetype, alloc_flags, pcp, list); > + } > + } > +#endif > if (page) { > __count_zid_vm_events(PGALLOC, page_zonenum(page), 1); > zone_statistics(preferred_zone, zone); That's a bunch more code on a very hot path to serve an obscure feature which has a single obscure callsite. Can we instead put the burden on that callsite rather than upon everyone? For (dumb) example, teach __gup_longterm_locked() to put the page back if it's CMA and go get another one?