Re: [discuss] Re: 32-bit dma allocations on 64-bit platforms

From: William Lee Irwin III
Date: Thu Jun 24 2004 - 17:52:49 EST


/*
On Thu, Jun 24, 2004 at 02:54:41PM -0700, Andrew Morton wrote:
>> First thing to do is to identify some workload which needs the patch.

On Fri, Jun 25, 2004 at 12:21:50AM +0200, Andrea Arcangeli wrote:
> that's quite trivial, boot a 2G box, malloc(1G), bzero(1GB), swapoff -a,
> then the machine will lockup.
> Depending on the architecture (more precisely depending if it starts
> allocating ram from the end or from the start of the physical memory),
> you may have to load 1G of data into pagecache first, like reading from
> /dev/hda 1G (without closing the file) will work fine, then run the
> above malloc + bzero + swapoff.
> Most people will never report this because everybody has swap and they
> simply run a lot slower than they could run if they didn't need to pass
> through the swap device to relocate memory because memory would been allocated
> in the right place in the first place. this plus the various oom killer
> breakages that gets dominated by the nr_swap_pages > 0 check, are the
> reasons 2.6 is unusable w/o swap.

Have you tried with 2.6.7? The following program fails to trigger anything
like what you've mentioned, though granted it was a 512MB allocation on
a 1GB machine. swapoff(2) merely fails.
*/

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <strings.h>
#include <sys/swap.h>

int main(int argc, char * const argv[])
{
int i;
long pagesize, physpages;
size_t size;
void *p;

pagesize = sysconf(_SC_PAGE_SIZE);
if (pagesize < 0) {
perror("failed to determine pagesize");
exit(EXIT_FAILURE);
}
physpages = sysconf(_SC_PHYS_PAGES);
if (physpages < 0) {
perror("failed to determine physical memory capacity");
exit(EXIT_FAILURE);
}
if ((size_t)(physpages/2) > SIZE_MAX/pagesize) {
fprintf(stderr, "insufficient virtualspace capacity\n");
exit(EXIT_FAILURE);
}
size = (physpages/2)*pagesize;
p = malloc(size);
if (!p) {
perror("allocation failure");
exit(EXIT_FAILURE);
}
bzero(p, size);
for (i = 1; i < argc; ++i) {
if (swapoff(argv[i]))
perror("swapoff failure");
fprintf(stderr, "failed to offline %s\n", argv[i]);
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/