From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 744FB31DD97 for ; Fri, 3 Jul 2026 08:35:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783067760; cv=none; b=EoXU6GILlwK76AwIVzM921MdkPc2Hv1Q2VGg8emASHiJN7RlHuV6Ayp/bnbnItD25r96CIbGsLa3niMy+Rt9SJ3GB1EH7xyXBq8PnWNAggcODB/szMmhztfiAmpxv3+fWVqmYsry8ewmn3eG/WAqy+qoueQLNqPvscoUnoXLQuc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783067760; c=relaxed/simple; bh=eQxnoDMMeS8zqLXEAn5onMUP1uws6doz7zxSRSRHohU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=R094xB9UVKehY5J3il4i2GujHuVyIimjx5yRy2idj1/CQe7gzGa9vVwamo41KH3INJ1X+SkN4Ur5FS1sago4xBausvB3MeGj/fjm/OQrPX3Zuref68Eali9CnP6PTkaMG9fdgRz34ZN+tKfNGtcKcvB0F2Am7qmFJbb6xURhZws= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Tb4Op9JW; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Tb4Op9JW" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-493bb510ce4so2024555e9.1 for ; Fri, 03 Jul 2026 01:35:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1783067757; x=1783672557; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=7WAbGtIrI1EcfzFik+M+qn8x7M7ZtMBRYdePiOvKmF8=; b=Tb4Op9JW37Lmr2DG4vEYzeEJG3hjor3+Yon/W712PqmIVFYj9N5pOVpBXYMsKO31ZZ TBhAzp2TMKKJMDQ1lR1VhchL6+rmevTkG68vaJY6fpeagCiEsx33iz+Z7ZTcEAJTdxNT zE9J5yU1q/rIL47vOxpGLrBz+aYbMWzHt1pKRsl2OoI/DNbUyajo/Y/CHGjNOFKplZRF 2FrJqQoeVRRqSI6lyw/jV+LkW4C5AawbIAFewP9GsU8N34FJqEQK+lXxoHbW7AVttYrK e95S+f4IygosXRL5MbXeDymMSVlpWCroP/3+U6gergXPhpI4xkv7X+B+8g2ZuZDLwsBP d9YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783067757; x=1783672557; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7WAbGtIrI1EcfzFik+M+qn8x7M7ZtMBRYdePiOvKmF8=; b=eAiZPpXI9GwTvbPElcLC1VD7dmzPmV/dsT7ocyuVH/j/rRYs9ujrpj+C13vhkPFomD Tk78yECYobTFcPIsc2RXghQO9iKuvMvKqZeOMV0oGCmaM/BAwzu9QZnREOR3r63MtA/Y 6PEgWa9ZgMJfLcOkPnLXfLxUJ88Xc93Ts2GiwCyqnKeut0+y9NOJ1iSOWGBYxbFYh8s9 rNUQcrEkeJ2nAA+BibyBaW8SeuapVta2as53/3HGnJm8Ou6T0qjimWE55UweM7kNWiq6 MBKl+9r9PteJbbEpqbZ3I2oX1dbG9SwVfQZHf62MsnDPGq7yLnaI2fjwrkhVJ46BPNPa QDfA== X-Forwarded-Encrypted: i=1; AFNElJ9GeOQIQt5rNUDZ3Wc0rJtEQfKxmDIeVmnvnseE9NbbmKYYnTR/wud3tZIOdy3GdBf3eBdSA6JqK36cM24=@vger.kernel.org X-Gm-Message-State: AOJu0Yz3/y6/W4FbLI/4i+1dNk8hmszVGbbivjCw/nlUJ4kcZEUYy5eg MpXe5eddB9e0CkVqSAh+xzRIpCzucOevqobNhYs5ER159hN27pVYyGGNdz3SbZOdwb0= X-Gm-Gg: AfdE7cle76P3dKpRkxKE9bdF+QuF0G4fGhbfS6OZnTIo8cLUgdIbK1xTv6TAgKc2QlE aYgFwNFY+akCMl5CWoDQ9gt9A899b+Oa+3hl0uvkwIBka8xqu4q5icdn7f25nghCgjs2bhfjbGF s+he4mIDipvcpDOPtjxOfSNVWwQ2U4hsr9eIYjGQzns7L9QrUwia/N2o5jdpEhCDGujKBvYO2La MMe2ZilFamQdqxBMgg9/9QMaY5R9UAm5988kNje3GxW2D4ipDfPguCn4F617oOfIKrIz+zJlz6w da0znzaoSWjsD7OfcFrSJ6N0S4CknBaQwTqyGXlneh1JafjIlyWS0hCVrQplv0R92DknZlqF8uY pVGOAcFJ/8wF5iR4ODJMh3l4Uu8ys64IOJet/HeQXKLeCUNzXRzd0teX2doq78EPggXGmqo2Sv5 T1l62mtt1+xD0z0bOg0Tdt7Ys2A4+jkLVhoQ3W3pleejsLKs/Wb3Sv6H5S0Q== X-Received: by 2002:a05:600c:8590:b0:492:4363:e7eb with SMTP id 5b1f17b1804b1-493c2ba4f75mr109823175e9.32.1783067756702; Fri, 03 Jul 2026 01:35:56 -0700 (PDT) Received: from [192.168.178.47] (aftr-62-216-205-241.dynamic.mnet-online.de. [62.216.205.241]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493ccd9d620sm33431275e9.1.2026.07.03.01.35.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Jul 2026 01:35:56 -0700 (PDT) Message-ID: <5b03b1d4-c094-437c-8934-64b94bd37138@suse.com> Date: Fri, 3 Jul 2026 10:35:55 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/4] scsi: ipr: use kmalloc() to allocate IPR dump buffer memory To: Mike Rapoport , Brian King Cc: "Martin K. Petersen" , Brian King , "James E.J. Bottomley" , Matthew Wilcox , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, wenxiong@linux.ibm.com References: <20260630-b4-scsi-v1-0-494fb37ebe7b@kernel.org> <20260630-b4-scsi-v1-3-494fb37ebe7b@kernel.org> <7c8f0e70-f49c-4614-af95-002fb2be11ba@suse.com> Content-Language: en-US From: Hannes Reinecke In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 7/3/26 9:49 AM, Mike Rapoport wrote: > On Thu, Jul 02, 2026 at 09:55:56AM +0300, Mike Rapoport wrote: >> On Wed, Jul 01, 2026 at 04:03:48PM -0500, Brian King wrote: >>> On 7/1/26 4:52 AM, Mike Rapoport wrote: >>>> On Wed, Jul 01, 2026 at 09:03:06AM +0200, Hannes Reinecke wrote: >>>>> On 6/30/26 12:54 PM, Mike Rapoport (Microsoft) wrote: >>>>>> IPR dump machinery allocates memory to save adapter's crash dump using >>>>>> __get_free_page(). >>>>>> >>>>>> This memory 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. >>>>>> >>>>>> Replace use of __get_free_page() with kmalloc(). >>>>>> >>>>>> Link: https://lore.kernel.org/all/635405e4-9423-4a25-a6e7-e03c8ea0bcbe@redhat.com >>>>>> Signed-off-by: Mike Rapoport (Microsoft) >>>>>> --- >>>>>> drivers/scsi/ipr.c | 4 ++-- >>>>>> 1 file changed, 2 insertions(+), 2 deletions(-) >>>>>> >>>>>> diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c >>>>>> index d207e5e81afe..5a212bfdeec2 100644 >>>>>> --- a/drivers/scsi/ipr.c >>>>>> +++ b/drivers/scsi/ipr.c >>>>>> @@ -2893,7 +2893,7 @@ static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg, >>>>>> (ioa_dump->hdr.len + bytes_copied) < max_dump_size) { >>>>>> if (ioa_dump->page_offset >= PAGE_SIZE || >>>>>> ioa_dump->page_offset == 0) { >>>>>> - page = (__be32 *)__get_free_page(GFP_ATOMIC); >>>>>> + page = kmalloc(PAGE_SIZE, GFP_ATOMIC); >>>>>> if (!page) { >>>>>> ipr_trace; >>>>>> @@ -3226,7 +3226,7 @@ static void ipr_release_dump(struct kref *kref) >>>>>> spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); >>>>>> for (i = 0; i < dump->ioa_dump.next_page_index; i++) >>>>>> - free_page((unsigned long) dump->ioa_dump.ioa_data[i]); >>>>>> + kfree(dump->ioa_dump.ioa_data[i]); >>>>>> vfree(dump->ioa_dump.ioa_data); >>>>>> kfree(dump); >>>>>> >>>>> >>>>> I _think_ we can replace this with kvmalloc, and allocate the entire >>>>> dump buffer in one go. Once switched to kmalloc() it's kinda pointless >>>>> to allocate separate page-sized buffers here. >>>> >>>> kmalloc() performance is on par with __get_free_page(), but kvmalloc() >>>> would be slower if it falls back to vmalloc(). >>>> >>>> I'm not familiar with the driver to say if this could be an issue here. >>> >>> This code only runs when the adapter has hit a fatal error, so should be >>> extremely rare. The memory is getting allocated while the storage adapter >>> is in a failed state, so anything running on the system at the time could >>> be stalled until recovery is completed. This memory is allocated and should >>> be freed soon after the adapter recovers. In order for this code to >>> run, the iprdump daemon must be running, which will then read out the dump >>> after the adapter is recovered, and write it to disk, after which time, the >>> ipr driver will free the kernel memory. >> >> Thanks for the explanation! >> >> So the allocation is not on the hot path and it seems to me that >> performance differences between kmalloc() and slower vmalloc() won't move a >> needle relatively to the entire dump procedure. > > I looked more closely at the code. Currently the dump continues as long as > it can allocate memory and even if memory for the entire buffer is not > available there still will be some data in the dump. > > With a single allocation that may be as large as 80M > (IPR_FMT3_MAX_IOA_DUMP_SIZE), an allocation failure would mean no data > would be dumped at all. > > I think the current model is better than using a single kvmalloc() > allocation for the entire buffer. > > I'm going to send v2 that keeps kmalloc() and only changes GFP_ATOMIC to > GFP_NOIO if there are no objections. > Fair point. You can add: Reviewed-by: Hannes Reinecke Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.com +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich