[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20170208180447.GO2267@bombadil.infradead.org>
Date: Wed, 8 Feb 2017 10:04:47 -0800
From: Matthew Wilcox <willy@...radead.org>
To: James Bottomley <James.Bottomley@...senPartnership.com>
Cc: Minchan Kim <minchan@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org, linux-arch@...r.kernel.org,
sergey.senozhatsky@...il.com, iamjoonsoo.kim@....com,
ngupta@...are.org, zhouxianrong@...wei.com, zhouxiyu@...wei.com,
weidu.du@...wei.com, zhangshiming5@...wei.com,
Mi.Sophia.Wang@...wei.com, won.ho.park@...wei.com, liw@....fi
Subject: Re: memfill
On Tue, Feb 07, 2017 at 11:07:34AM -0800, James Bottomley wrote:
> > /**
> > * memfill - Fill a region of memory with the given value
> > * @s: Pointer to the start of the region.
> > * @v: The word to fill the region with.
> > * @n: The size of the region.
> > *
> > * Differs from memset() in that it fills with an unsigned long
> > instead of
> > * a byte. The pointer and the size must be aligned to unsigned
> > long.
> > */
> > void memfill(unsigned long *s, unsigned long v, size_t n)
>
> If we're going to do this, are you sure we wouldn't be wanting a string
> fill instead of a memfill (because filling either by byte or long looks
> a bit restrictive) assuming static strings that we can tell the compile
> time size of, it would be easy for generic code to optimise.
When you say 'string fill', do you mean this?
void memfill(void *dst, size_t dsz, void *src, size_t ssz)
{
if (ssz == 1) {
memset(dst, *(unsigned char *)src, dsz);
} else if (ssz == sizeof(short)) {
memset_s(dst, *(unsigned short *)src, dsz);
} else if (ssz == sizeof(int)) {
memset_i(dst, *(unsigned int *)src, dsz);
} else if (ssz == sizeof(long)) {
memset_l(dst, *(unsigned long *)src, dsz);
} else {
while (dsz >= ssz) {
memcpy(dst, src, ssz);
dsz -= ssz;
dst += ssz;
}
if (dsz)
memcpy(dst. src. dsz);
}
}
(with memset_[sil] being obvious, I hope). Possibly some variation on
this to optimise compile-time constant dsz.
I have no objection to that. Indeed, it would match Lars Wirzenius'
memfill() definition (if not implementation) which makes me quite happy.
Powered by blists - more mailing lists