mirror of
				https://git.haproxy.org/git/haproxy.git/
				synced 2025-11-04 10:31:14 +01:00 
			
		
		
		
	CLEANUP: fd: make use of ha_aligned_alloc() for the fdtab
We've forcefully aligned the fdtab in commit 97ea9c49f1 ("BUG/MEDIUM:
fd: always align fdtab[] to 64 bytes"), but now we don't need such hacks
anymore thanks to ha_aligned_alloc(). Let's use it and get rid of
fdtab_addr.
			
			
This commit is contained in:
		
							parent
							
								
									746e77d000
								
							
						
					
					
						commit
						5e2837cfb4
					
				
							
								
								
									
										13
									
								
								src/fd.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/fd.c
									
									
									
									
									
								
							@ -117,7 +117,6 @@ THREAD_LOCAL int poller_rd_pipe = -1; // Pipe to wake the thread
 | 
				
			|||||||
int poller_wr_pipe[MAX_THREADS] __read_mostly; // Pipe to wake the threads
 | 
					int poller_wr_pipe[MAX_THREADS] __read_mostly; // Pipe to wake the threads
 | 
				
			||||||
 | 
					
 | 
				
			||||||
volatile int ha_used_fds = 0; // Number of FD we're currently using
 | 
					volatile int ha_used_fds = 0; // Number of FD we're currently using
 | 
				
			||||||
static struct fdtab *fdtab_addr;  /* address of the allocated area containing fdtab */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* adds fd <fd> to fd list <list> if it was not yet in it */
 | 
					/* adds fd <fd> to fd list <list> if it was not yet in it */
 | 
				
			||||||
void fd_add_to_fd_list(volatile struct fdlist *list, int fd)
 | 
					void fd_add_to_fd_list(volatile struct fdlist *list, int fd)
 | 
				
			||||||
@ -1166,14 +1165,12 @@ int init_pollers()
 | 
				
			|||||||
	int p;
 | 
						int p;
 | 
				
			||||||
	struct poller *bp;
 | 
						struct poller *bp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((fdtab_addr = calloc(1, global.maxsock * sizeof(*fdtab) + 64)) == NULL) {
 | 
						/* always provide an aligned fdtab */
 | 
				
			||||||
 | 
						if ((fdtab = ha_aligned_zalloc(64, global.maxsock * sizeof(*fdtab))) == NULL) {
 | 
				
			||||||
		ha_alert("Not enough memory to allocate %d entries for fdtab!\n", global.maxsock);
 | 
							ha_alert("Not enough memory to allocate %d entries for fdtab!\n", global.maxsock);
 | 
				
			||||||
		goto fail_tab;
 | 
							goto fail_tab;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	vma_set_name(fdtab_addr, global.maxsock * sizeof(*fdtab) + 64, "fd", "fdtab_addr");
 | 
						vma_set_name(fdtab, global.maxsock * sizeof(*fdtab), "fd", "fdtab");
 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* always provide an aligned fdtab */
 | 
					 | 
				
			||||||
	fdtab = (struct fdtab*)((((size_t)fdtab_addr) + 63) & -(size_t)64);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((polled_mask = calloc(global.maxsock, sizeof(*polled_mask))) == NULL) {
 | 
						if ((polled_mask = calloc(global.maxsock, sizeof(*polled_mask))) == NULL) {
 | 
				
			||||||
		ha_alert("Not enough memory to allocate %d entries for polled_mask!\n", global.maxsock);
 | 
							ha_alert("Not enough memory to allocate %d entries for polled_mask!\n", global.maxsock);
 | 
				
			||||||
@ -1214,7 +1211,7 @@ int init_pollers()
 | 
				
			|||||||
 fail_info:
 | 
					 fail_info:
 | 
				
			||||||
	free(polled_mask);
 | 
						free(polled_mask);
 | 
				
			||||||
 fail_polledmask:
 | 
					 fail_polledmask:
 | 
				
			||||||
	free(fdtab_addr);
 | 
						ha_aligned_free(fdtab);
 | 
				
			||||||
 fail_tab:
 | 
					 fail_tab:
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1235,7 +1232,7 @@ void deinit_pollers() {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ha_free(&fdinfo);
 | 
						ha_free(&fdinfo);
 | 
				
			||||||
	ha_free(&fdtab_addr);
 | 
						ha_aligned_free(fdtab);
 | 
				
			||||||
	ha_free(&polled_mask);
 | 
						ha_free(&polled_mask);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user