From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95F223EE1FC for ; Thu, 23 Jul 2026 07:50:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784793050; cv=none; b=CuRCnWqLQD1ax6xm6rNz7s1lS3xd/OO5zDde6nLR5/NNyROEnLH5ODa/sHoxO+mEa9JITAAsfyws8Y73+G+MYBFh/iYWUUZmLkeID/d3eIBtEC2o0bbvgs4KhoLAppKie1VRuRrn5L4NtnO8PEEq4LkTckpfU+SptIPtm3xmw8U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784793050; c=relaxed/simple; bh=Zgp0JxJpZVQ4R23UVsZn8BAcBQHqNs/OP/pPyRV7AMg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fsWX7omUNXxnA6u8nvQXz5L+79THuEO1YfXAK9r4cPqZeooc7eE7z7Q0dw3I0Y38MIc3tgTL/vjgWoV4905CJ7E849BEOPV2CS/6AHsHRuDZKl9zlmiGSnbvkFix3gJTB6CYChylSQNxgPbWDim9lZOFwcM2DY0zt4zB9qh241Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jyescas.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=LsJa9WBS; arc=none smtp.client-ip=209.85.215.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jyescas.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="LsJa9WBS" Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-c856470fe9fso369892a12.2 for ; Thu, 23 Jul 2026 00:50:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784793049; x=1785397849; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=BP29+lWQBrVZ0v/6HzcYEqD+hOgCbSaZezdh9Is5B8A=; b=LsJa9WBSBG0SvMjkYEY9E6vc3Z3nD2AKP4TDo5CQWTPd02Y1f8enBpvj7sU7zfUeAD yGYaH7ZkS1oGuspkNKUuhNdthttud6j6rwBXiJhSMy1FFLFi5AKlYWYM2Yn/bHkJuB7i SZfhcj0vcfPWUY+cR+p/iryqBn8VckM3KXMc+uUrSSVXsraN+X189SpVanUf5VdFAe5F qSRZ0ZFofdOdknTmLX+tJrV67dbV5CkQ9qrERU2UlA3SsQheSmCDkoFzZblirploYGbb rXlHebMan0liHf0dqjbz8ho74CCkfj6Y3JlWBhp/OI8Q28nepWohq/Ri6wL7yoaw4KYV wWgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784793049; x=1785397849; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BP29+lWQBrVZ0v/6HzcYEqD+hOgCbSaZezdh9Is5B8A=; b=EWdfTh4WU4Wygyhf6rADU/l4TAOlY1CUpV4KXRCt/hhMcCsCJ4bbJc5zEGjzC5hHbF d4xyKTRNKUsA7TpOVc3iu2dbSYryUagLAg+mjh9strCUO/QLxsZ3eGWmck8vbKAZVNc2 da2QgTwx7/CzwPZ4PQ8yZUA0nGO+RyodhDGajiLyPlwp6tJBpKWbMpg4GuOWpC9eA6Xp ZIRruJ29pOsYxv4CtU6tqrKZ6Ey9yhDufhotqlxD86uASjFjxhCwmU7ulFruU+qAwVOp vGgKw3gnL0nHcvte92mWKQJVX8fbph2UIj6KEJt2FaJ0u5XJqY8io36qEtL9uzLH4UIc LbGg== X-Forwarded-Encrypted: i=1; AHgh+Ro3u3CdGiqe2edX9EJjZg8dx/vq0I2XScl777aYP2Z0mvCjp4/t4IdNOaDV+gHGcNsrdwb8ziS0jLFFGn0=@vger.kernel.org X-Gm-Message-State: AOJu0YyzxMjkwcqHuUsQ6FFGjlAmpv5Jg3cpP+MxHsFuURR2GOGQZYja uQZ2VYexNPNV3RLOnrs5Mt0tZ68VBIKIP9ayaviDH5pItH5hhY5beoGNO7ANOGLFj/ySDLGnVBV 5Bg6iycIjHw== X-Received: from dly25-n2.prod.google.com ([2002:a05:701b:2059:20b0:13b:9d65:a542]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3e85:b0:38e:5741:5173 with SMTP id 98e67ed59e1d1-38ec662cdc5mr1864402a91.29.1784793048525; Thu, 23 Jul 2026 00:50:48 -0700 (PDT) Date: Thu, 23 Jul 2026 00:47:16 -0700 In-Reply-To: <20260723074854.1013941-1-jyescas@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260723074854.1013941-1-jyescas@google.com> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260723074854.1013941-13-jyescas@google.com> Subject: [RFC PATCH 12/16] mm: Define the make_alloc() function From: Juan Yescas To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , open list , "open list:MEMORY MANAGEMENT - CORE" Cc: jyescas@google.com, android-mm@google.com, fvdl@google.com, tkjos@google.com, minchan@google.com, dskiba@google.com, open list , "open list:MEMORY MANAGEMENT - CORE" Content-Type: text/plain; charset="UTF-8" The make_alloc() is the core function that performs the allocation. The tasks of this function are: - Call the Buddy allocator to make the allocation. - Store the details of the allocation in struct page_alloc. - Insert the struct page_alloc in an xarray using the allocation id as key. If something fails during the allocation, the pages and cache will be freed. Signed-off-by: Juan Yescas --- mm/page_alloc_hogger.c | 71 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index d91f49880f8d..7f6eebdd5197 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -97,6 +97,18 @@ struct dentry *mmdir; +/** + * atomic_long_t allocs_file_seq - Represents the naming sequence used for + * allocation files. + */ +atomic_long_t allocs_file_seq = ATOMIC_INIT(0); + +/** + * allocs_xa - Represent the xarray that contains the actual allocations perform + * by this driver. + */ +static DEFINE_XARRAY(allocs_xa); + /** * struct req_alloc - Represents the requested allocation * @node_idx: The Node index to allocate from. @@ -174,6 +186,47 @@ inline void set_migrate_type_to_alloc_from(int migrate_type, gfp_t *flags_ptr) } } +static int make_alloc(struct req_alloc *req, + gfp_t flags, unsigned long *alloc_id) +{ + struct page_alloc *pa; + struct page *page; + char new_alloc_name[12]; + int ret; + + page = alloc_pages_node_noprof(req->node_idx, flags, req->order); + if (page) { + pa = kmem_cache_alloc(page_alloc_cache, GFP_KERNEL); + if (!pa) { + ret = -ENOMEM; + goto free_pages; + } + + *alloc_id = atomic_long_inc_return(&allocs_file_seq); + ret = xa_insert(&allocs_xa, *alloc_id, pa, GFP_KERNEL); + if (ret) + goto free_page_alloc; + + snprintf(new_alloc_name, sizeof(new_alloc_name), "%lu", + *alloc_id); + + pa->req_alloc = req; + pa->page = page; + } else { + return -ENOMEM; + } + + return 0; + +free_page_alloc: + kmem_cache_free(page_alloc_cache, pa); + +free_pages: + __free_pages(page, pa->req_alloc->order); + + return ret; +} + /** * req_page_alloc_write() - Allocates the pages on the requested node, zone, * order and migrate type. Once the allocation is performed, a file is created @@ -183,10 +236,12 @@ static ssize_t req_page_alloc_write(struct file *file, const char __user *ubuf, size_t cnt, loff_t *ppos) { struct req_alloc *req = file->private_data; + unsigned long alloc_id; unsigned long nr_pages_allocs; unsigned long *allocs_ids; gfp_t flags = 0; int ret; + int i; ret = kstrtoul_from_user(ubuf, cnt, 10, &nr_pages_allocs); if (ret) @@ -200,7 +255,23 @@ static ssize_t req_page_alloc_write(struct file *file, const char __user *ubuf, set_zone_to_alloc_from(req->zone_idx, &flags); set_migrate_type_to_alloc_from(req->migrate_type, &flags); + for (i = 0; i < nr_pages_allocs; i++) { + ret = make_alloc(req, flags, &alloc_id); + if (ret) + goto free_allocs; + + allocs_ids[i] = alloc_id; + } + + kfree(allocs_ids); + return cnt; + +free_allocs: + + kfree(allocs_ids); + + return ret; } static const struct file_operations req_page_alloc_fops = { -- 2.55.0.229.g6434b31f56-goog