All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Heiko Carstens <hca@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Alexandra Winter <wintera@linux.ibm.com>,
	Aswin Karuvally <aswin@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Harald Freudenberger <freude@linux.ibm.com>,
	Holger Dengler <dengler@linux.ibm.com>,
	Jan Hoeppner <hoeppner@linux.ibm.com>,
	Stefan Haberland <sth@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	linux-s390@vger.kernel.org
Subject: Re: [PATCH 2/6] s390/dasd: replace get_zeroed_page() with kzalloc()
Date: Sun, 31 May 2026 13:35:41 +0300	[thread overview]
Message-ID: <ahwO_UCxePgb0SwL@kernel.org> (raw)
In-Reply-To: <20260529101522.26496Bbe-hca@linux.ibm.com>

On Fri, May 29, 2026 at 12:15:22PM +0200, Heiko Carstens wrote:
> On Thu, May 28, 2026 at 10:09:50AM +0300, Mike Rapoport (Microsoft) wrote:
> > DASD driver uses get_zeroed_page() to allocate pages for the Extended Error
> > Reporting software ring buffer and for a scratch buffer for formatting
> > sense dump diagnostic text.
> > 
> > These buffers can be allocated with kmalloc() as there's nothing special
> > about it to go directly to the page allocator.
> > 
> > kmalloc() provides a better API that does not require ugly casts and
> > kfree() does not need to know the size of the freed object.
> > 
> > Performance difference between kmalloc() and __get_free_pages() is not
> > measurable as both allocators take an object/page from a per-CPU list for
> > fast path allocations.
> > 
> > For the slow path the performance is anyway determined by the amount of
> > reclaim involved rather than by what allocator is used.
> > 
> > Replace use of get_zeroed_page() with kzalloc() and free_page() with
> > kfree().
> > 
> > Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > ---
> >  drivers/s390/block/dasd_eckd.c | 12 ++++++------
> >  drivers/s390/block/dasd_eer.c  |  4 ++--
> >  2 files changed, 8 insertions(+), 8 deletions(-)
> 
> ...
> 
> >  static void dasd_eckd_dump_sense(struct dasd_device *device,
> > @@ -6958,7 +6958,7 @@ dasd_eckd_init(void)
> >  		kfree(pe_handler_worker);
> >  		kfree(dasd_reserve_req);
> >  		kfree(dasd_vol_info_req);
> > -		free_page((unsigned long)rawpadpage);
> > +		kfree(rawpadpage);
> >  	}
> >  	return ret;
> >  }
> > @@ -6969,7 +6969,7 @@ dasd_eckd_cleanup(void)
> >  	ccw_driver_unregister(&dasd_eckd_driver);
> >  	kfree(pe_handler_worker);
> >  	kfree(dasd_reserve_req);
> > -	free_page((unsigned long)rawpadpage);
> > +	kfree(rawpadpage);
> >  }
> 
> This is not correct. The allocation is still done with __get_free_page().

Right, I didn't mean to touch rawpadpage yet.
cherry-pick from the large set went wrong :(
 
> I'm not sure about the whole approach / effort, since this allows for subtle
> bugs where pages are allocated and freed at non-obvious locations. All of that
> works now, but these conversions may lead to subtle bugs (this particular one
> is not subtle and easy to spot).
> 
> Is the net gain of this conversion really worth it?

My initial intention a few month ago was to remove ugly casts [1], but then
willy pointed out that Linus objected to something like this [2] and it
looks like more than a decade old technical debt.

Largely, anything that doesn't need struct page (or a memdesc in the
future) should just use kmalloc() or kvmalloc() to allocate memory.
kmalloc() guarantees alignment, physical contiguity and working
virt_to_phys() and beside nicer API that returns void * on alloc and
doesn't require to know the allocation size on free, kmalloc() provides
better debugging capabilities than page allocator.

Another thing is that touching these allocation sites gives the reviewers
opportunity to see if a PAGE_SIZE buffer is actually needed or maybe
another size is appropriate.

For larger allocations that don't need physically contiguous memory
kvmalloc() can be a better option that __get_free_pages() because under
memory pressure it's is easier to allocate several order-0 pages than a
physically contiguous chunk with the same number of pages.

And last, but not least, removing needless calls to page allocator should
help with memdesc (aka project folio) conversion. There will be way less
places to audit to see if the user was actually using struct page.

[1] https://lore.kernel.org/all/20251018093002.3660549-1-rppt@kernel.org/
[2] https://lore.kernel.org/all/CA+55aFwp4iy4rtX2gE2WjBGFL=NxMVnoFeHqYa2j1dYOMMGqxg@mail.gmail.com/ 

-- 
Sincerely yours,
Mike.

  reply	other threads:[~2026-05-31 10:35 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-28  7:09 [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc() Mike Rapoport (Microsoft)
2026-05-28  7:09 ` [PATCH 1/6] s390/con3270: replace __get_free_page() " Mike Rapoport (Microsoft)
2026-05-29 10:26   ` Heiko Carstens
2026-05-28  7:09 ` [PATCH 2/6] s390/dasd: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
2026-05-29 10:15   ` Heiko Carstens
2026-05-31 10:35     ` Mike Rapoport [this message]
2026-05-28  7:09 ` [PATCH 3/6] s390/hvc_iucv: " Mike Rapoport (Microsoft)
2026-05-29 10:26   ` Heiko Carstens
2026-05-28  7:09 ` [PATCH 4/6] s390/qeth: " Mike Rapoport (Microsoft)
2026-05-28 14:17   ` Alexandra Winter
2026-05-29 10:23   ` Heiko Carstens
2026-05-31 10:17     ` Mike Rapoport
2026-05-29 11:09   ` Heiko Carstens
2026-05-29 11:15     ` Vlastimil Babka (SUSE)
2026-05-28  7:09 ` [PATCH 5/6] s390/trng: replace __get_free_page() with kmalloc() Mike Rapoport (Microsoft)
2026-05-29 10:29   ` Heiko Carstens
2026-05-28  7:09 ` [PATCH 6/6] s390/zcrypt: replace get_zeroed_page() with kzalloc() Mike Rapoport (Microsoft)
2026-05-29  8:29   ` Harald Freudenberger
2026-05-29 10:28   ` Heiko Carstens
2026-05-28 14:48 ` [PATCH 0/6] s390/drivers: replace __get_free_pages() call with kmalloc() Alexander Gordeev
2026-05-28 15:16   ` Mike Rapoport
2026-05-29  6:21     ` Alexander Gordeev
2026-05-29  7:13       ` Mike Rapoport

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ahwO_UCxePgb0SwL@kernel.org \
    --to=rppt@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=aswin@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=dengler@linux.ibm.com \
    --cc=freude@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=hoeppner@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --cc=sth@linux.ibm.com \
    --cc=svens@linux.ibm.com \
    --cc=wintera@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.